Exponential Basic 2.4.0.1 Exponential Basic CMS — PHP Class Reference

ezorder.php
Go to the documentation of this file.
1 <?php
3 //
4 // $Id: ezorder.php 9830 2003-06-03 06:18:07Z jhe $
5 //
6 // Definition of eZOrder class
7 //
8 // Created on: <28-Sep-2000 16:40:01 bf>
9 //
10 // This source file is part of Exponential Basic, publishing software.
11 //
12 // Copyright (C) 1999-2001 eZ Systems. All rights reserved.
13 //
14 // This program is free software; you can redistribute it and/or
15 // modify it under the terms of the GNU General Public License
16 // as published by the Free Software Foundation; either version 2
17 // of the License, or (at your option) any later version.
18 //
19 // This program is distributed in the hope that it will be useful,
20 // but WITHOUT ANY WARRANTY; without even the implied warranty of
21 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 // GNU General Public License for more details.
23 //
24 // You should have received a copy of the GNU General Public License
25 // along with this program; if not, write to the Free Software
26 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, US
27 //
28
31
36 // include_once( "classes/ezdb.php" );
37 // include_once( "classes/ezdatetime.php" );
38
39 // include_once( "eztrade/classes/ezpreorder.php" );
40 // include_once( "eztrade/classes/ezorderstatustype.php" );
41 // include_once( "eztrade/classes/ezorderstatus.php" );
42 // include_once( "eztrade/classes/ezorderitem.php" );
43 // include_once( "eztrade/classes/ezshippingtype.php" );
44 // include_once( "eztrade/classes/ezvoucherused.php" );
45
46 // include_once( "ezuser/classes/ezuser.php" );
47
48 // include_once( "ezaddress/classes/ezaddress.php" );
49
50
51 class eZOrder
52 {
59 function __construct( $id="" )
60 {
61 $this->IsExported = 0;
62 $this->PersonID = 0;
63 $this->CompanyID = 0;
64
65 if ( $id != "" )
66 {
67 $this->ID = $id;
68 $this->get( $this->ID );
69 }
70 $ini =& eZINI::instance( 'site.ini' );
71 $this->checkups = $ini->variable( "eZTradeMain", "UPSOFF" );
72 }
73
77 function store()
78 {
79 $db =& eZDB::globalDatabase();
80 $db->begin();
81
82 $this->TextPaymentMethod = $db->escapeString( $this->PaymentMethod );
83 $comment = $db->escapeString( $this->Comment );
84
85 if ( !isset( $this->ID ) )
86 {
87 $timeStamp =& (new eZDateTime())->timeStamp( true );
88 $db->lock( "eZTrade_Order" );
89 $nextID = $db->nextID( "eZTrade_Order", "ID" );
90 $ret[] = $db->query( "INSERT INTO eZTrade_Order
91 (ID,
92 UserID,
93 ShippingAddressID,
94 BillingAddressID,
95 PaymentMethod,
96 IsExported,
97 ShippingVAT,
98 ShippingTypeID,
99 Date,
100 IsVATInc,
101 ShippingCharge,
102 PersonID,
103 CompanyID,
104 Comment )
105 VALUES
106 ('$nextID',
107 '$this->UserID',
108 '$this->ShippingAddressID',
109 '$this->BillingAddressID',
110 '$this->PaymentMethod',
111 '$this->IsExported',
112 '$this->ShippingVAT',
113 '$this->ShippingTypeID',
114 '$timeStamp',
115 '$this->IsVATInc',
116 '$this->ShippingCharge',
117 '$this->PersonID',
118 '$this->CompanyID',
119 '$comment' )" );
120 $db->unlock();
121 $db->commit();
122 $db->begin();
123 $this->ID = $nextID;
124
125 // store the status
126 $statusType = new eZOrderStatusType( );
127 $statusType = $statusType->getByName( "intl-order received" );
128
129 $status = new eZOrderStatus();
130 $status->setType( $statusType );
131
132 $status->setOrderID( $this->ID );
133
134 $user =& eZUser::currentUser();
135 // print( $user->id() );
136
137 $status->setAdmin( $user );
138 $status->store();
139 }
140 else
141 {
142 $db->query( "UPDATE eZTrade_Order SET
143 UserID='$this->UserID',
144 ShippingAddressID='$this->ShippingAddressID',
145 BillingAddressID='$this->BillingAddressID',
146 PaymentMethod='$this->PaymentMethod',
147 IsExported='$this->IsExported',
148 ShippingVAT='$this->ShippingVAT',
149 ShippingTypeID='$this->ShippingTypeID',
150 Date=Date,
151 ShippingCharge='$this->ShippingCharge',
152 PersonID='$this->PersonID',
153 CompanyID='$this->CompanyID',
154 Comment='$comment'
155 WHERE ID='$this->ID'
156 " );
157
158 }
159
160 // eZDB::finish( $ret, $db );
161 return true;
162 }
163
167 function delete()
168 {
169 $db =& eZDB::globalDatabase();
170
171 $items = $this->items();
172 $db->begin();
173
174 if ( $items )
175 {
176 $i = 0;
177 foreach ( $items as $item )
178 {
179 $item->delete();
180 }
181 }
182 $ret[] = $db->query( "DELETE FROM eZTrade_OrderStatus WHERE OrderID='$this->ID'" );
183 $ret[] = $db->query( "DELETE FROM eZUser_UserShippingLink WHERE AddressID='$this->ShippingAddressID'" );
184 $ret[] = $db->query( "DELETE FROM eZTrade_Order WHERE ID='$this->ID'" );
185
186 eZDB::finish( $ret, $db );
187
188 return true;
189 }
190
191
195 function get( $id="" )
196 {
197 $db =& eZDB::globalDatabase();
198
199 $ret = false;
200
201 if ( $id != "" )
202 {
203 $db->array_query( $cart_array, "SELECT * FROM eZTrade_Order WHERE ID='$id'" );
204 if ( count( $cart_array ) > 1 )
205 {
206 die( "Error: Cart's with the same ID was found in the database. This shouldent happen." );
207 }
208 else if ( count( $cart_array ) == 1 )
209 {
210 $this->ID =& $cart_array[0][$db->fieldName( "ID" )];
211 $this->UserID =& $cart_array[0][$db->fieldName( "UserID" )];
212 $this->ShippingAddressID =& $cart_array[0][$db->fieldName( "ShippingAddressID" )];
213 $this->BillingAddressID =& $cart_array[0][$db->fieldName( "BillingAddressID" )];
214 $this->ShippingCharge =& $cart_array[0][$db->fieldName( "ShippingCharge" )];
215 $this->ShippingVAT =& $cart_array[0][$db->fieldName( "ShippingVAT" )];
216 $this->ShippingTypeID =& $cart_array[0][$db->fieldName( "ShippingTypeID" )];
217 $this->PaymentMethod =& $cart_array[0][$db->fieldName( "PaymentMethod" )];
218 $this->Date =& $cart_array[0][$db->fieldName( "Date" )];
219 $this->IsVATInc =& $cart_array[0][$db->fieldName( "IsVATInc" )];
220 $this->IsExported =& $cart_array[0][$db->fieldName( "IsExported" )];
221 $this->PersonID =& $cart_array[0][$db->fieldName( "PersonID" )];
222 $this->CompanyID =& $cart_array[0][$db->fieldName( "CompanyID" )];
223 $this->Comment =& $cart_array[0][$db->fieldName( "Comment" )];
224 $ret = true;
225 }
226 }
227 return $ret;
228 }
229
235 function &getAll( $offset = 0, $limit = 40, $OrderBy = "Date" )
236 {
237 switch ( strtolower( $OrderBy ) )
238 {
239 case "no":
240 {
241 $OrderBy = "ID DESC";
242 break;
243 }
244 case "created":
245 {
246 $OrderBy = "Date DESC";
247 break;
248 }
249 case "modified":
250 {
251 $OrderBy = "Altered DESC";
252 break;
253 }
254 case "status":
255 {
256 $OrderBy = "StatusID";
257 break;
258 }
259 default:
260 {
261 $OrderBy = "Date DESC";
262 break;
263 }
264 }
265 $db =& eZDB::globalDatabase();
266
267 $return_array = array();
268 $order_array = array();
269
270 $db->array_query( $order_array,
271 "SELECT * FROM ( SELECT eZTrade_Order.ID as ID,
272 eZTrade_Order.Date as Date,
273 max( eZTrade_OrderStatus.Altered ) as Altered,
274 max( eZTrade_OrderStatus.StatusID ) as StatusID
275 FROM eZTrade_Order, eZTrade_PreOrder, eZTrade_OrderStatus
276 WHERE eZTrade_Order.ID = eZTrade_OrderStatus.OrderID AND
277 eZTrade_Order.ID = eZTrade_PreOrder.OrderID
278 GROUP BY eZTrade_Order.ID, eZTrade_Order.Date ) AS tmp_table ORDER BY $OrderBy",
279 array( "Limit" => $limit, "Offset" => $offset ) );
280
281 for ( $i = 0; $i < count( $order_array ); $i++ )
282 {
283 $return_array[$i] = new eZOrder( $order_array[$i][$db->fieldName( "ID" )], 0 );
284 }
285
286 return $return_array;
287 }
288
294 function &getByUser( $offset = 0, $limit = 40, $OrderBy = "Date", $user = false )
295 {
296 switch ( strtolower( $OrderBy ) )
297 {
298 case "no":
299 {
300 $OrderBy = "ID";
301 break;
302 }
303 case "created":
304 {
305 $OrderBy = "Date";
306 break;
307 }
308 case "modified":
309 {
310 $OrderBy = "Altered";
311 break;
312 }
313 case "status":
314 {
315 $OrderBy = "StatusID";
316 break;
317 }
318 default:
319 {
320 $OrderBy = "Date";
321 break;
322 }
323 }
324 $db =& eZDB::globalDatabase();
325
326 $return_array = array();
327 $order_array = array();
328
329 $userID = $user->id();
330
331 $db->array_query( $order_array,
332 "SELECT eZTrade_Order.ID as ID,
333 eZTrade_Order.Date as Date,
334 max( eZTrade_OrderStatus.Altered ) as Altered,
335 max( eZTrade_OrderStatus.StatusID ) as StatusID
336 FROM eZTrade_Order, eZTrade_PreOrder, eZTrade_OrderStatus
337 WHERE eZTrade_Order.ID = eZTrade_OrderStatus.OrderID AND UserID='$userID' AND
338 eZTrade_Order.ID = eZTrade_PreOrder.OrderID
339 GROUP BY eZTrade_Order.ID, eZTrade_Order.Date
340 ORDER BY $OrderBy",
341 array( "Limit" => $limit, "Offset" => $offset ) );
342
343 for ( $i = 0; $i < count( $order_array ); $i++ )
344 {
345 $return_array[$i] = new eZOrder( $order_array[$i][$db->fieldName( "ID" )], 0 );
346 }
347
348 return $return_array;
349 }
350
356 function &getCountByUser( $user = false, $OrderBy = false )
357 {
358 switch ( strtolower( $OrderBy ) )
359 {
360 case "no":
361 {
362 $OrderBy = "ID";
363 break;
364 }
365 case "created":
366 {
367 $OrderBy = "Date";
368 break;
369 }
370 case "modified":
371 {
372 $OrderBy = "Altered";
373 break;
374 }
375 case "status":
376 {
377 $OrderBy = "StatusID";
378 break;
379 }
380 default:
381 {
382 $OrderBy = "Date";
383 break;
384 }
385 }
386 $db =& eZDB::globalDatabase();
387
388 $return_array = array();
389 $order_array = array();
390
391 $userID = $user->id();
392
393 $db->query_single( $res,
394 "SELECT COUNT(eZTrade_Order.ID) as Count
395 FROM eZTrade_Order, eZTrade_OrderStatus, eZTrade_PreOrder
396 WHERE eZTrade_Order.ID = eZTrade_OrderStatus.OrderID AND
397 eZTrade_Order.ID = eZTrade_PreOrder.OrderID AND UserID='$userID' " );
398
399 return $res[$db->fieldName( "Count" )];
400 }
401
402 static public function &getByContact( $contact, $is_person = true, $offset = 0, $limit = 40 )
403 {
404 $db =& eZDB::globalDatabase();
405
406 $return_array = array();
407 $order_array = array();
408
409 if ( $is_person )
410 $condition = "PersonID";
411 else
412 $condition = "CompanyID";
413
414 $db->array_query( $order_array,
415 "SELECT eZTrade_Order.ID FROM eZTrade_Order, eZTrade_PreOrder WHERE $condition='$contact' AND " .
416 "eZTrade_Order.ID = eZTrade_PreOrder.OrderID",
417 array( "Limit" => $limit, "Offset" => $offset ) );
418
419 for ( $i = 0; $i < count( $order_array ); $i++ )
420 {
421 $return_array[$i] = new eZOrder( $order_array[$i][$db->fieldName( "ID" )], 0 );
422 }
423
424 return $return_array;
425 }
426
430 function &getByCustomer( $user )
431 {
432 $db =& eZDB::globalDatabase();
433
434 $return_array = array();
435 $order_array = array();
436
437 $userID = $user->id();
438 $db->array_query( $order_array,
439 "SELECT eZTrade_Order.ID FROM eZTrade_Order, eZTrade_PreOrder WHERE
440 UserID='$userID' AND eZTrade_Order.ID = eZTrade_PreOrder.OrderID" );
441
442 for ( $i = 0; $i < count( $order_array ); $i++ )
443 {
444 $return_array[$i] = new eZOrder( $order_array[$i][$db->fieldName( "ID" )] );
445 }
446
447 return $return_array;
448 }
449
453 function &getNew()
454 {
455 $db =& eZDB::globalDatabase();
456
457 $return_array = array();
458 $order_array = array();
459
460 $db->array_query( $order_array,
461 "SELECT eZTrade_Order.ID FROM eZTrade_Order, eZTrade_PreOrder
462 WHERE IsExported='0' AND eZTrade_Order.ID = eZTrade_PreOrder.OrderID" );
463
464 for ( $i = 0; $i < count( $order_array ); $i++ )
465 {
466 $return_array[$i] = new eZOrder( $order_array[$i][$db->fieldName( "ID" )] );
467 }
468
469 return $return_array;
470 }
471
477 function &search( $queryText, $offset=0, $limit=20 )
478 {
479 $db =& eZDB::globalDatabase();
480
481 $return_array = array();
482 $order_array = array();
483
484 $db->array_query( $order_array, "SELECT eZTrade_Order.ID
485 FROM eZTrade_Order, eZTrade_PreOrder
486 WHERE eZTrade_Order.ID LIKE '%$queryText%' AND
487 eZTrade_Order.ID = eZTrade_PreOrder.OrderID",
488 array( "Limit" => $limit, "Offset" => $offset ) );
489
490 for ( $i = 0; $i < count( $order_array ); $i++ )
491 {
492 $return_array[$i] = new eZOrder( $order_array[$i][$db->fieldName( "ID" )], 0 );
493 }
494
495 return $return_array;
496 }
497
501 function &getSearchCount( $queryText )
502 {
503 $db =& eZDB::globalDatabase();
504
505 $db->array_query( $order_array, "SELECT count(eZTrade_Order.ID) as Count
506 FROM eZTrade_Order, eZTrade_PreOrder
507 WHERE eZTrade_Order.ID LIKE '%$queryText%' AND
508 eZTrade_Order.ID = eZTrade_PreOrder.OrderID" );
509
510 $ret = 0;
511 if ( count( $order_array ) == 1 )
512 {
513 $ret = $order_array[0][$db->fieldName( "Count" )];
514 }
515
516 return $ret;
517 }
518
522 function &getTotalCount()
523 {
524 $db =& eZDB::globalDatabase();
525
526 $db->array_query( $order_array, "SELECT count(eZTrade_Order.ID) as Count
527 FROM eZTrade_Order, eZTrade_PreOrder
528 WHERE eZTrade_Order.ID = eZTrade_PreOrder.OrderID" );
529
530 $ret = 0;
531 if ( count( $order_array ) == 1 )
532 {
533 $ret = $order_array[0][$db->fieldName( "Count" )];
534 }
535
536 return $ret;
537 }
538
542 function &date()
543 {
544 $dateTime = new eZDateTime();
545 $dateTime->setTimeStamp( $this->Date );
546 return $dateTime;
547 }
548
552 function id()
553 {
554 return $this->ID;
555 }
556
562 function &user()
563 {
564 $ret = false;
565
566 $user = new eZUser( );
567 if ( $user->get( $this->UserID ) )
568 $ret = $user;
569
570 return $ret;
571 }
572
576 function shippingCharge()
577 {
578 return $this->ShippingCharge;
579 }
580
584 function shippingVAT()
585 {
586 return $this->ShippingVAT;
587 }
588
592 function &shippingAddress()
593 {
594 $shippingAddress = new eZAddress( $this->ShippingAddressID );
595
596 return $shippingAddress;
597 }
598
602 function isVATInc()
603 {
604 if ( $this->IsVATInc == 1 )
605 return true;
606 else
607 return false;
608 }
609
610
616 function &shippingUser()
617 {
618 // check the owner of the address
619
620 $db =& eZDB::globalDatabase();
621
622 $address_array = array();
623
624 $retUser = false;
625
626 if ( $this->PersonID == 0 && $this->CompanyID == 0 )
627 {
628 $db->array_query( $address_array,
629 "SELECT * FROM eZUser_UserShippingLink WHERE AddressID='$this->ShippingAddressID'" );
630
631 if ( count( $address_array ) == 1 )
632 {
633 $retUser = new eZUser( $address_array[0][$db->fieldName( "UserID" )] );
634 }
635 else
636 {
637 print( "Error: eZOrder::shippingUser() " . count( $address_array ) . " users found, should be 1." );
638 }
639 return $retUser;
640 }
641 return false;
642 }
643
647 function &billingAddress()
648 {
649 $billingAddress = new eZAddress( $this->BillingAddressID );
650
651 return $billingAddress;
652 }
653
657 function &comment()
658 {
659 return $this->Comment;
660 }
661
667 function &shippingType()
668 {
669 $ret = false;
670
671 if( $this->checkups == 1 )
672 {
673 $ret = $this->ShippingTypeID;
674 }
675 else
676 {
677 if ( $this->ShippingTypeID > 0 )
678 {
679 $ret = new eZShippingType( $this->ShippingTypeID );
680 }
681 }
682
683 return $ret;
684 }
685
689 function paymentMethod()
690 {
691 return $this->PaymentMethod;
692 }
693
694
695 /* Returns the authorization code.
696
697 function authCode()
698 {
699 return $this->AuthCode;
700 }
701 */
706 function isExported( $value )
707 {
708 if ( $this->IsExported == 1 )
709 return true;
710 else
711 return false;
712 }
713
717 function personID()
718 {
719 return $this->PersonID;
720 }
721
725 function companyID()
726 {
727 return $this->CompanyID;
728 }
729
733 function setPaymentMethod( $value )
734 {
735 if ( is_array ( $value ) )
736 {
737 $i = 0;
738 foreach ( $value as $item )
739 {
740 if ( $i == 0 )
741 $method = $item;
742 else
743 $method .= "," . $item;
744 }
745 $value = $method;
746 }
747 $this->PaymentMethod = $value;
748 }
749
750 /* function setAuthCode( $value )
751 {
752 $this->AuthCode = $value;
753 } */
754
758 function setUser( $user )
759 {
760 if ( is_a( $user, "eZUser" ) )
761 {
762 $this->UserID = $user->id();
763 }
764 }
765
769 function setComment( $value )
770 {
771 $this->Comment = $value;
772 }
773
775 // possible "User Info Swap"
776
780 function setShippingAddress( $shippingAddress, $user )
781 {
782 if ( is_a( $shippingAddress, "eZAddress" ) )
783 {
784 $shippingAddress =& $shippingAddress->copy();
785 $this->ShippingAddressID = $shippingAddress->id();
786 $userID = $user->id();
787
788 $db =& eZDB::globalDatabase();
789 $db->begin();
790
791 // $userID = $user->id();
792
793 $db->lock( "eZUser_UserShippingLink" );
794 $nextID = $db->nextID( "eZUser_UserShippingLink", "ID" );
795
796 $ret[] = $db->query( "INSERT INTO eZUser_UserShippingLink
797 (ID,
798 UserID,
799 AddressID )
800 VALUES
801 ('$nextID',
802 '$userID',
803 '$this->ShippingAddressID') " );
804 $db->unlock();
805 eZDB::finish( $ret, $db );
806 }
807 }
808
812 function setBillingAddress( $billingAddress, $user )
813 {
814 if ( is_a( $billingAddress, "eZAddress" ) )
815 {
816 $billingAddress =& $billingAddress->copy();
817 $this->BillingAddressID = $billingAddress->id();
818 }
819 }
820
824 function setShippingCharge( $value )
825 {
826 $this->ShippingCharge = $value;
827
828 setType( $this->ShippingCharge, "double" );
829 }
830
834 function setShippingVAT( $value )
835 {
836 $this->ShippingVAT = $value;
837
838 setType( $this->ShippingVAT, "double" );
839 }
840
844 function setIsVATInc( $value )
845 {
846 if ( $value )
847 $this->IsVATInc = 1;
848 else
849 $this->IsVATInc = 0;
850 }
851
852
856 function setStatus( $type )
857 {
858 if ( is_a( $type, "eZOrderStatusType" ) )
859 {
860 $this->OrderStatus_ = $type->id();
861 }
862 }
863
867 function setShippingTypeID( $type )
868 {
869 $this->ShippingTypeID = $type;
870 }
871
876 function setIsExported( $value )
877 {
878 if ( $value == true )
879 $this->IsExported = 1;
880 else
881 $this->IsExported = 0;
882 }
883
887 function setPersonID( $userID )
888 {
889 if ( is_a( $userID, "eZUser" ) )
890 $id = $userID->ID();
891 else
892 $id = $userID;
893 if ( is_numeric( $id ) )
894 {
895 $this->PersonID = $id;
896 }
897 }
898
902 function setCompanyID( $id )
903 {
904 if ( is_numeric( $id ) )
905 {
906 $this->CompanyID = $id;
907 }
908 }
909
913 function &initialStatus( )
914 {
915 $db =& eZDB::globalDatabase();
916 $statusType = new eZOrderStatusType();
917
918 $statusType->getByName( "intl-order received" );
919
920 $db->array_query( $status_array, "SELECT ID FROM eZTrade_OrderStatus
921 WHERE OrderID='$this->ID'
922 ORDER BY Altered DESC" );
923 $ret = false;
924 if ( count( $status_array ) )
925 {
926 $ret = new eZOrderStatus( $status_array[0][$db->fieldName( "ID" )]);
927 }
928 return $ret;
929 }
930
934 function &lastStatus( )
935 {
936 $db =& eZDB::globalDatabase();
937 $statusType = new eZOrderStatusType();
938
939 $statusType->getByName( "intl-order received" );
940
941 $db->array_query( $status_array, "SELECT ID FROM eZTrade_OrderStatus
942 WHERE OrderID='$this->ID'
943 ORDER BY Altered DESC" );
944 $ret = false;
945 if ( count( $status_array ) )
946 {
947 $ret = new eZOrderStatus( $status_array[0][$db->fieldName( "ID" )] );
948 }
949 return $ret;
950 }
951
955 function &statusHistory()
956 {
957 $db =& eZDB::globalDatabase();
958
959 $statusType = new eZOrderStatusType();
960
961 $statusType->getByName( "intl-order received" );
962
963 $db->array_query( $status_array, "SELECT ID FROM eZTrade_OrderStatus
964 WHERE OrderID='$this->ID'
965 ORDER BY Altered" );
966 $ret = array();
967 foreach ( $status_array as $status )
968 {
969 $ret[] = new eZOrderStatus( $status[$db->fieldName( "ID" )] );
970 }
971 return $ret;
972
973 }
974
978 function &items()
979 {
980 $ret = array();
981
982 $db =& eZDB::globalDatabase();
983
984 $db->array_query( $order_array, "SELECT * FROM
985 eZTrade_OrderItem
986 WHERE OrderID='$this->ID'" );
987
988 if ( count( $order_array ) > 0 )
989 {
990 $return_array = array();
991 foreach ( $order_array as $item )
992 {
993 $return_array[] = new eZOrderItem( $item[$db->fieldName( "ID" )] );
994 }
995 $ret = $return_array;
996 }
997
998 return $ret;
999 }
1000
1004 function &usedVouchers()
1005 {
1006 $ret = array();
1007
1008 $db =& eZDB::globalDatabase();
1009
1010 $db->array_query( $order_array, "SELECT ID FROM
1011 eZTrade_VoucherUsed
1012 WHERE OrderID='$this->ID'" );
1013
1014 if ( count( $order_array ) > 0 )
1015 {
1016 $return_array = array();
1017 foreach ( $order_array as $item )
1018 {
1019 $return_array[] = new eZVoucherUsed( $item[$db->fieldName( "ID" )] );
1020 }
1021 $ret = $return_array;
1022 }
1023
1024 return $ret;
1025 }
1026
1027
1031 function totalPrice( $user = false )
1032 {
1033 $retPrice = 0;
1034 $db =& eZDB::globalDatabase();
1035
1036 $db->array_query( $order_item_array, "SELECT Price, Count FROM
1037 eZTrade_OrderItem
1038 WHERE OrderID='$this->ID'" );
1039
1040 foreach ( $order_item_array as $item )
1041 {
1042 $price = $item[$db->fieldName("Price")];
1043 // $price = $price * $item["Count"];
1044
1045 $retPrice += $price;
1046 }
1047 return $retPrice;
1048 }
1049
1053 function totalPriceIncVAT()
1054 {
1055 return $this->totalPrice() + $this->totalVAT();
1056 }
1057
1061 function totalVAT()
1062 {
1063 $retPrice = 0;
1064 $db =& eZDB::globalDatabase();
1065
1066 $db->array_query( $order_item_array, "SELECT VAT, Count FROM
1067 eZTrade_OrderItem
1068 WHERE OrderID='$this->ID'" );
1069
1070 foreach ( $order_item_array as $item )
1071 {
1072 $price = $item[$db->fieldName( "VAT" )];
1073
1074 // $price = $price * $item["Count"];
1075
1076 $retPrice += $price;
1077 }
1078
1079 return $retPrice;
1080 }
1081
1085 function isOwner( &$user )
1086 {
1087 $db =& eZDB::globalDatabase();
1088
1089 $userID = $user->id();
1090 $ret = false;
1091 $db->query_single( $res, "SELECT ID FROM eZTrade_Order
1092 WHERE ID='$this->ID' AND UserID='$userID'" );
1093 if ( is_numeric( $res[$db->fieldName( "ID" )] ) )
1094 $ret = true;
1095
1096 return $ret;
1097 }
1098
1099
1103 function &mostPopularProduct()
1104 {
1105 $db =& eZDB::globalDatabase();
1106 $ret = array();
1107
1108 $db->array_query( $product_array,
1109 "SELECT ProductID, Count(ProductID) AS Count, Sum( Count ) AS RealCount
1110 FROM eZTrade_OrderItem GROUP BY ProductID
1111 ORDER BY RealCount DESC" );
1112
1113 foreach ( $product_array as $item )
1114 {
1115 $ret[] = array( "ProductID" => $item[$db->fieldName( "ProductID" )],
1116 "Count" => $item[$db->fieldName( "Count" )],
1117 "RealCount" => $item[$db->fieldName( "RealCount" )] );
1118 }
1119
1120 return $ret;
1121 }
1122
1126 function &expiringOrders( $startdate, $time = 86400 )
1127 {
1128 if ( is_a( $startdate, "eZDate" ) || is_a( $startdate, "eZDateTime" ) )
1129 {
1130 $startdate = $startdate->timeStamp();
1131 }
1132 $enddate = $startdate + $time;
1133
1134 $db =& eZDB::globalDatabase();
1135 $db->array_query( $orders, "SELECT ID FROM eZTrade_OrderItem
1136 WHERE ExpiryDate >= '" . $startdate . "'
1137 AND ExpiryDate < '" . $enddate . "'" );
1138 $return_array = array();
1139
1140 foreach ( $orders as $order )
1141 {
1142 $return_array[] = $order[$db->fieldName( "ID" )];
1143 }
1144 return $return_array;
1145 }
1146
1147 static public function soldProducts( $product )
1148 {
1149 if ( is_a( $product, "eZProduct" ) )
1150 $product = $product->ID();
1151
1152 $db =& eZDB::globalDatabase();
1153
1154 $db->array_query( $res, "SELECT SUM( Count ) AS C FROM eZTrade_OrderItem WHERE ProductID='$product'" );
1155 return $res[0][$db->fieldName( "C" )];
1156 }
1157
1163 function orderTotals( &$tax, &$total )
1164 {
1165 $items = $this->items( );
1166
1167 $tax = array();
1168 $total = array();
1169
1170 $totalIncTax = 0;
1171 $totalExTax = 0;
1172
1173 foreach ( $items as $item )
1174 {
1175 $product =& $item->product();
1176 $vatPercentage = (int)$product->vatPercentage();
1177
1178 $tax["$vatPercentage"] = array();
1179 $tax["$vatPercentage"]["basis"] = false;
1180 $tax["$vatPercentage"]["tax"] = false;
1181 $tax["$vatPercentage"]["percentage"] = false;
1182
1183 $exTax = $item->correctPrice( true, true, false );
1184 $incTax = $item->correctPrice( true, true, true );
1185
1186 $totalExTax += $exTax;
1187 $totalIncTax += $incTax;
1188
1189 $tax["$vatPercentage"]["basis"] += $exTax;
1190 $tax["$vatPercentage"]["tax"] += $incTax - $exTax;
1191 $tax["$vatPercentage"]["percentage"] = $vatPercentage;
1192 }
1193
1194 $total["subinctax"] = $totalIncTax;
1195 $total["subextax"] = $totalExTax;
1196 $total["subtax"] = $totalIncTax - $totalExTax;
1197
1198 $shippingCost = $this->ShippingCharge;
1199 $shippingVAT = $this->ShippingVAT;
1200
1201 if ( $shippingVAT && $shippingCost )
1202 {
1203 $shippingVATPercentage = round( $shippingVAT / ( ( $shippingCost - $shippingVAT ) / 100 ), 2 );
1204 }
1205 else
1206 $shippingVATPercentage = 0;
1207
1208 $tax["$shippingVATPercentage"] = array();
1209 $tax["$shippingVATPercentage"]["basis"] = false;
1210 $tax["$shippingVATPercentage"]["tax"] = false;
1211 $tax["$shippingVATPercentage"]["percentage"] = false;
1212
1213 $tax["$shippingVATPercentage"]["basis"] += $shippingCost - $shippingVAT;
1214 $tax["$shippingVATPercentage"]["tax"] += $shippingVAT;
1215 $tax["$shippingVATPercentage"]["percentage"] = $shippingVATPercentage;
1216
1217 //RS $total["shipinctax"] = $shippingCost;
1218 //RS $total["shipextax"] = $shippingCost - $shippingVAT;
1219 $total["shiptax"] = $shippingVAT;
1220
1221 $total["shipinctax"] = $shippingCost + $shippingVAT;
1222 $total["shipextax"] = $shippingCost;
1223
1224 $total["inctax"] = $total["subinctax"] + $total["shipinctax"];
1225 $total["extax"] = $total["subextax"] + $total["shipextax"];
1226 $total["tax"] = $total["subtax"] + $total["shiptax"];
1227 }
1228
1229
1235 function voucherTotal( &$tax, &$total, $voucherItem=false )
1236 {
1237 $tax = "";
1238 $total = "";
1239
1240 if ( is_a ( $voucherItem, "eZVoucherUsed" ) )
1241 $voucher =& $voucherItem->voucher();
1242 else
1243 $voucher =& $voucherItem;
1244
1245 $product =& $voucher->product();
1246 $vatPercentage = $product->vatPercentage();
1247 $exTax = $voucherItem->correctPrice( false );
1248 $incTax = $voucherItem->correctPrice( true );
1249
1250 $totalExTax += $exTax;
1251 $totalIncTax += $incTax;
1252
1253 $tax["$vatPercentage"]["basis"] += $exTax;
1254 $tax["$vatPercentage"]["tax"] += $incTax - $exTax;
1255 $tax["$vatPercentage"]["percentage"] = $vatPercentage;
1256
1257 $total["subinctax"] = $totalIncTax;
1258 $total["subextax"] = $totalExTax;
1259 $total["subtax"] = $totalIncTax - $totalExTax;
1260 $total["inctax"] = $total["subinctax"];
1261 $total["extax"] = $total["subextax"];
1262 $total["tax"] = $total["subtax"];
1263 }
1264
1271 static public function &customers( $searchText = false )
1272 {
1273 $db =& eZDB::globalDatabase();
1274
1275 $return_array = array();
1276 $user_array = array();
1277
1278 if ( $searchText )
1279 $searchQuery = "AND (eZUser_User.FirstName LIKE '%$searchText%' OR
1280 eZUser_User.LastName LIKE '%$searchText%' OR
1281 eZUser_User.Login LIKE '%$searchText%' OR
1282 eZUser_User.Email LIKE '%$searchText%')";
1283 else
1284 $searchQuery = "";
1285
1286 $db->array_query( $user_array, "SELECT eZTrade_Order.UserID, eZUser_User.FirstName FROM eZTrade_Order, eZTrade_PreOrder, eZUser_User
1287 WHERE eZTrade_Order.UserID=eZUser_User.ID AND eZTrade_Order.ID = eZTrade_PreOrder.OrderID
1288 $searchQuery GROUP BY eZTrade_Order.UserID, eZUser_User.FirstName ORDER BY eZUser_User.FirstName " );
1289
1290 for ( $i = 0; $i < count( $user_array ); $i++ )
1291 {
1292 $return_array[$i] = new eZUser( $user_array[$i][$db->fieldName( "UserID" )] );
1293 }
1294
1295 return $return_array;
1296 }
1297
1298 var $ID;
1299 var $UserID;
1300 var $ShippingAddressID;
1301 var $BillingAddressID;
1303 var $ShippingCharge;
1305 var $ShippingVAT;
1306 var $PaymentMethod;
1307 //var $AuthCode;
1308 var $Date;
1309 var $PersonID;
1310 var $CompanyID;
1311 var $IsVATInc;
1312 var $Comment;
1313
1314 var $ShippingTypeID;
1315 var $OrderStatus_;
1316 var $IsExported;
1317 var $TextPaymentMethod;
1318 var $checkups;
1319
1320 }
1321
1322 ?>
$i
$i
Definition: admin/adlist.php:91
$shippingCost
foreach( $items as $item) $shippingCost
Definition: admin/orderview.php:267
$items
$items
Definition: admin/orderview.php:211
$userID
else $userID
Definition: appointmentedit.php:121
$dateTime
$dateTime
Definition: authorview.php:77
$status
$status
Definition: bugedit.php:473
$total
else $total["inctax"]
Definition: checkout.php:1359
$shippingAddress
$shippingAddress
Definition: checkout.php:615
eZAddress
Definition: ezaddress.php:42
eZDB\finish
static finish(&$resultArray, &$db)
Definition: ezdb.php:204
eZDB\globalDatabase
static & globalDatabase()
Definition: ezdb.php:134
eZDateTime
Definition: ezdatetime.php:55
eZOrderItem
Definition: ezorderitem.php:48
eZOrderStatusType
Definition: ezorderstatustype.php:44
eZOrderStatus
Definition: ezorderstatus.php:44
eZOrder
Definition: ezorder.php:52
eZOrder\isExported
isExported( $value)
Definition: ezorder.php:706
eZOrder\totalVAT
totalVAT()
Definition: ezorder.php:1061
eZOrder\setCompanyID
setCompanyID( $id)
Definition: ezorder.php:902
eZOrder\voucherTotal
voucherTotal(&$tax, &$total, $voucherItem=false)
Definition: ezorder.php:1235
eZOrder\mostPopularProduct
& mostPopularProduct()
Definition: ezorder.php:1103
eZOrder\$PersonID
$PersonID
Definition: ezorder.php:1309
eZOrder\$ID
$ID
Definition: ezorder.php:1298
eZOrder\customers
static & customers( $searchText=false)
Definition: ezorder.php:1271
eZOrder\$IsVATInc
$IsVATInc
Definition: ezorder.php:1311
eZOrder\getTotalCount
& getTotalCount()
Definition: ezorder.php:522
eZOrder\$BillingAddressID
$BillingAddressID
Definition: ezorder.php:1301
eZOrder\$CompanyID
$CompanyID
Definition: ezorder.php:1310
eZOrder\lastStatus
& lastStatus()
Definition: ezorder.php:934
eZOrder\$IsExported
$IsExported
Definition: ezorder.php:1316
eZOrder\$Comment
$Comment
Definition: ezorder.php:1312
eZOrder\soldProducts
static soldProducts( $product)
Definition: ezorder.php:1147
eZOrder\usedVouchers
& usedVouchers()
Definition: ezorder.php:1004
eZOrder\totalPrice
totalPrice( $user=false)
Definition: ezorder.php:1031
eZOrder\setStatus
setStatus( $type)
Definition: ezorder.php:856
eZOrder\$OrderStatus_
$OrderStatus_
Definition: ezorder.php:1315
eZOrder\setShippingAddress
setShippingAddress( $shippingAddress, $user)
Definition: ezorder.php:780
eZOrder\getAll
& getAll( $offset=0, $limit=40, $OrderBy="Date")
Definition: ezorder.php:235
eZOrder\totalPriceIncVAT
totalPriceIncVAT()
Definition: ezorder.php:1053
eZOrder\id
id()
Definition: ezorder.php:552
eZOrder\search
& search( $queryText, $offset=0, $limit=20)
Definition: ezorder.php:477
eZOrder\user
& user()
Definition: ezorder.php:562
eZOrder\isOwner
isOwner(&$user)
Definition: ezorder.php:1085
eZOrder\initialStatus
& initialStatus()
Definition: ezorder.php:913
eZOrder\setComment
setComment( $value)
Definition: ezorder.php:769
eZOrder\isVATInc
isVATInc()
Definition: ezorder.php:602
eZOrder\statusHistory
& statusHistory()
Definition: ezorder.php:955
eZOrder\shippingCharge
shippingCharge()
Definition: ezorder.php:576
eZOrder\getSearchCount
& getSearchCount( $queryText)
Definition: ezorder.php:501
eZOrder\setIsVATInc
setIsVATInc( $value)
Definition: ezorder.php:844
eZOrder\paymentMethod
paymentMethod()
Definition: ezorder.php:689
eZOrder\expiringOrders
& expiringOrders( $startdate, $time=86400)
Definition: ezorder.php:1126
eZOrder\$ShippingVAT
$ShippingVAT
the VAT component of ShippingCharge
Definition: ezorder.php:1305
eZOrder\comment
& comment()
Definition: ezorder.php:657
eZOrder\$TextPaymentMethod
$TextPaymentMethod
Definition: ezorder.php:1317
eZOrder\shippingVAT
shippingVAT()
Definition: ezorder.php:584
eZOrder\$Date
$Date
Definition: ezorder.php:1308
eZOrder\setUser
setUser( $user)
Definition: ezorder.php:758
eZOrder\personID
personID()
Definition: ezorder.php:717
eZOrder\$ShippingTypeID
$ShippingTypeID
Definition: ezorder.php:1314
eZOrder\$ShippingCharge
$ShippingCharge
price inc. VAT
Definition: ezorder.php:1303
eZOrder\shippingAddress
& shippingAddress()
Definition: ezorder.php:592
eZOrder\$ShippingAddressID
$ShippingAddressID
Definition: ezorder.php:1300
eZOrder\setBillingAddress
setBillingAddress( $billingAddress, $user)
Definition: ezorder.php:812
eZOrder\$checkups
$checkups
Definition: ezorder.php:1318
eZOrder\companyID
companyID()
Definition: ezorder.php:725
eZOrder\setPaymentMethod
setPaymentMethod( $value)
Definition: ezorder.php:733
eZOrder\setIsExported
setIsExported( $value)
Definition: ezorder.php:876
eZOrder\getByUser
& getByUser( $offset=0, $limit=40, $OrderBy="Date", $user=false)
Definition: ezorder.php:294
eZOrder\items
& items()
Definition: ezorder.php:978
eZOrder\getCountByUser
& getCountByUser( $user=false, $OrderBy=false)
Definition: ezorder.php:356
eZOrder\store
store()
Definition: ezorder.php:77
eZOrder\getByContact
static & getByContact( $contact, $is_person=true, $offset=0, $limit=40)
Definition: ezorder.php:402
eZOrder\__construct
__construct( $id="")
Definition: ezorder.php:59
eZOrder\$PaymentMethod
$PaymentMethod
Definition: ezorder.php:1306
eZOrder\getNew
& getNew()
Definition: ezorder.php:453
eZOrder\date
& date()
Definition: ezorder.php:542
eZOrder\setShippingCharge
setShippingCharge( $value)
Definition: ezorder.php:824
eZOrder\billingAddress
& billingAddress()
Definition: ezorder.php:647
eZOrder\shippingType
& shippingType()
Definition: ezorder.php:667
eZOrder\shippingUser
& shippingUser()
Definition: ezorder.php:616
eZOrder\setShippingTypeID
setShippingTypeID( $type)
Definition: ezorder.php:867
eZOrder\setShippingVAT
setShippingVAT( $value)
Definition: ezorder.php:834
eZOrder\setPersonID
setPersonID( $userID)
Definition: ezorder.php:887
eZOrder\$UserID
$UserID
Definition: ezorder.php:1299
eZOrder\getByCustomer
& getByCustomer( $user)
Definition: ezorder.php:430
eZOrder\orderTotals
orderTotals(&$tax, &$total)
Definition: ezorder.php:1163
eZShippingType
Definition: ezshippingtype.php:45
eZUser
Definition: ezuser.php:76
eZUser\currentUser
static & currentUser()
Definition: ezuser.php:896
eZVoucherUsed
Definition: ezvoucherused.php:49
$ini
$ini
Definition: classes/admin/linklist.php:64
$item
$item
Definition: classes/admin/linklist.php:228
$type
$type
Definition: classes/admin/linkselect.php:220
$id
$id
Definition: companytypelist.php:193
$orders
$orders
Definition: customerview.php:87
$db
$db
Definition: ezarticle/user/authorlist.php:53
$user_array
while( $tmpTime->isGreater( $stopTime)) $user_array
Definition: ezcalendar/user/dayview.php:495
$limit
$limit
Definition: ezimagecatalogue/admin/imagelist.php:312
$ret
$ret
Definition: ezsitemanager/admin/filelist.php:88
$res
$res
Definition: ezstats/admin/cron.php:45
$offset
$offset
Definition: ezstats/admin/cron.php:51
$product
$product
Definition: homepage.php:202
$time
$time
Definition: homepage.php:327
$statusType
if(count( $usedVouchers) > 0) $statusType
Definition: orderedit.php:620
$shippingVAT
$shippingVAT
Definition: ordersendt.php:755
$billingAddress
$billingAddress
Definition: paypal.php:44
$price
$price
Definition: pricegroupedit.php:39
$order
$order
Definition: productreport.php:182
$OrderBy
$OrderBy
Definition: reciverpopup.php:21
$status_array
$status_array
Definition: todoedit.php:645
$user
$user
Definition: user/adlist.php:39
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.