00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039 include_once( "kernel/classes/ezpersistentobject.php" );
00040 include_once( "kernel/classes/ezproductcollection.php" );
00041 include_once( "kernel/classes/ezproductcollectionitem.php" );
00042 include_once( "kernel/classes/datatypes/ezuser/ezuser.php" );
00043 include_once( "kernel/classes/ezuserdiscountrule.php" );
00044 include_once( "kernel/classes/ezcontentobjecttreenode.php" );
00045 include_once( "kernel/classes/ezorderitem.php" );
00046
00047
00048 define ( "SHOW_NORMAL_ORDERS", 0 );
00049 define ( "SHOW_ARCHIVED_ORDERS", 1 );
00050 define ( "SHOW_ALL_ORDERS", 2 );
00051
00052 class eZOrder extends eZPersistentObject
00053 {
00054
00055
00056 function eZOrder( $row )
00057 {
00058 $this->eZPersistentObject( $row );
00059 $this->Status = null;
00060 }
00061
00062 function definition()
00063 {
00064 return array( "fields" => array( "id" => array( 'name' => 'ID',
00065 'datatype' => 'integer',
00066 'default' => 0,
00067 'required' => true ),
00068 "order_nr" => array( 'name' => "OrderNr",
00069 'datatype' => 'integer',
00070 'default' => 0,
00071 'required' => true ),
00072 "is_temporary" => array( 'name' => "IsTemporary",
00073 'datatype' => 'integer',
00074 'default' => 1,
00075 'required' => true ),
00076 "user_id" => array( 'name' => "UserID",
00077 'datatype' => 'integer',
00078 'default' => 0,
00079 'required' => true,
00080 'foreign_class' => 'eZUser',
00081 'foreign_attribute' => 'contentobject_id',
00082 'multiplicity' => '1..*' ),
00083 "productcollection_id" => array( 'name' => "ProductCollectionID",
00084 'datatype' => 'integer',
00085 'default' => 0,
00086 'required' => true,
00087 'foreign_class' => 'eZProductCollection',
00088 'foreign_attribute' => 'id',
00089 'multiplicity' => '1..*' ),
00090 "data_text_1" => array( 'name' => "DataText1",
00091 'datatype' => 'text',
00092 'default' => '',
00093 'required' => true ),
00094 "data_text_2" => array( 'name' => "DataText2",
00095 'datatype' => 'text',
00096 'default' => '',
00097 'required' => true ),
00098 "account_identifier" => array( 'name' => "AccountIdentifier",
00099 'datatype' => 'string',
00100 'default' => 'default',
00101 'required' => true ),
00102 "created" => array( 'name' => "Created",
00103 'datatype' => 'integer',
00104 'default' => 0,
00105 'required' => true ),
00106 "ignore_vat" => array( 'name' => "IgnoreVAT",
00107 'datatype' => 'integer',
00108 'default' => 0,
00109 'required' => true ),
00110 "email" => array( 'name' => "Email",
00111 'datatype' => 'string',
00112 'default' => '',
00113 'required' => true ),
00114 "status_id" => array( 'name' => 'StatusID',
00115 'datatype' => 'integer',
00116 'default' => 0,
00117 'required' => false,
00118 'foreign_class' => 'eZOrderStatus',
00119 'foreign_attribute' => 'id',
00120 'multiplicity' => '1..*' ),
00121 "status_modified" => array( 'name' => "StatusModified",
00122 'datatype' => 'integer',
00123 'default' => 0,
00124 'required' => true ),
00125 "status_modifier_id" => array( 'name' => "StatusModifierID",
00126 'datatype' => 'integer',
00127 'default' => 0,
00128 'required' => true,
00129 'foreign_class' => 'eZUser',
00130 'foreign_attribute' => 'contentobject_id',
00131 'multiplicity' => '1..*' ),
00132 "is_archived" => array( 'name' => "IsArchived",
00133 'datatype' => 'integer',
00134 'default' => 0,
00135 'required' => true ) ),
00136 'function_attributes' => array( 'status_name' => 'statusName',
00137 'status' => 'statusObject',
00138 'status_modification_list' => 'statusModificationList',
00139 'product_items' => 'productItems',
00140 'order_items' => 'orderItems',
00141 'product_total_inc_vat' => 'productTotalIncVAT',
00142 'product_total_ex_vat' => 'productTotalExVAT',
00143 'total_inc_vat' => 'totalIncVAT',
00144 'total_ex_vat' => 'totalExVAT',
00145 'user' => 'user',
00146 'account_view_template' => 'accountViewTemplate',
00147 'account_information' => 'accountInformation',
00148 'account_name' => 'accountName',
00149 'account_email' => 'accountEmail',
00150 'productcollection' => 'productCollection',
00151 'order_info' => 'orderInfo' ),
00152 "keys" => array( "id" ),
00153 "increment_key" => "id",
00154 "class_name" => "eZOrder",
00155 "name" => "ezorder" );
00156 }
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167 function &detachProductCollection()
00168 {
00169 $collection =& $this->productCollection();
00170 if ( !$collection )
00171 {
00172 $retValue = false;
00173 return $retValue;
00174 }
00175
00176 $db =& eZDB::instance();
00177 $db->begin();
00178 $newCollection =& $collection->copy();
00179 if ( !$newCollection )
00180 {
00181 $db->commit();
00182 $retValue = false;
00183 return $retValue;
00184 }
00185 $this->setAttribute( 'productcollection_id', $newCollection->attribute( 'id' ) );
00186 $this->store();
00187
00188 $db->commit();
00189 return $newCollection;
00190 }
00191
00192
00193
00194
00195 function &productCollection()
00196 {
00197 $collection = eZProductCollection::fetch( $this->attribute( 'productcollection_id' ) );
00198 return $collection;
00199 }
00200
00201 function fetch( $id, $asObject = true )
00202 {
00203 return eZPersistentObject::fetchObject( eZOrder::definition(),
00204 null,
00205 array( "id" => $id ),
00206 $asObject );
00207 }
00208
00209 function fetchList( $asObject = true )
00210 {
00211 return eZPersistentObject::fetchObjectList( eZOrder::definition(),
00212 null, null,
00213 array( "created" => "desc" ), null,
00214 $asObject );
00215 }
00216
00217 function activeByUserID( $userID, $asObject = true )
00218 {
00219 return eZPersistentObject::fetchObjectList( eZOrder::definition(),
00220 null,
00221 array( "user_id" => $userID,
00222 'is_temporary' => 0 ),
00223 array( "created" => "desc" ), null,
00224 $asObject );
00225 }
00226
00227 function getShowOrdersQuery( $show, $table = null )
00228 {
00229 $table = ( is_null( $table ) ? "" : $table . "." );
00230
00231 switch( $show )
00232 {
00233 case SHOW_NORMAL_ORDERS : return $table."is_archived = '0'"; break;
00234 case SHOW_ARCHIVED_ORDERS : return $table."is_archived = '1'"; break;
00235 case SHOW_ALL_ORDERS :
00236 default : return $table."is_archived IN (0, 1)"; break;
00237 }
00238 }
00239
00240
00241
00242
00243
00244 function &active( $asObject = true, $offset, $limit, $sortField = "created", $sortOrder = "asc", $show = SHOW_NORMAL_ORDERS )
00245 {
00246 if ( $sortField == "user_name" )
00247 {
00248 $db =& eZDB::instance();
00249
00250 $db_params = array();
00251 $db_params["offset"] =(int) $offset;
00252 $db_params["limit"] =(int) $limit;
00253 $sortOrder = $db->escapeString( $sortOrder );
00254
00255 $query = "SELECT ezorder.*
00256 FROM
00257 ezorder,
00258 ezcontentobject
00259 WHERE
00260 ".eZOrder::getShowOrdersQuery( $show, "ezorder" )." AND
00261 ezorder.is_temporary = '0' AND
00262 ezcontentobject.id = ezorder.user_id
00263 ORDER BY ezcontentobject.name $sortOrder";
00264 $orderArray = $db->arrayQuery( $query, $db_params );
00265 if ( $asObject )
00266 {
00267 $retOrders = array();
00268 foreach ( $orderArray as $order )
00269 {
00270 $order = new eZOrder( $order );
00271 $retOrders[] = $order;
00272 }
00273 return $retOrders;
00274 }
00275 else
00276 return $orderArray;
00277 }
00278 else
00279 {
00280 $where['is_temporary'] = 0;
00281 if ( $show != SHOW_ALL_ORDERS )
00282 {
00283 $where['is_archived'] = $show;
00284 }
00285
00286 $objectList = eZPersistentObject::fetchObjectList( eZOrder::definition(),
00287 null,
00288 $where ,
00289 array( $sortField => $sortOrder ),
00290 array( 'offset' => $offset,
00291 'length' => $limit ), $asObject );
00292 return $objectList;
00293 }
00294 }
00295
00296
00297
00298
00299 function activeCount( $show = SHOW_NORMAL_ORDERS )
00300 {
00301 $db =& eZDB::instance();
00302
00303 $query = 'SELECT count( * ) AS count FROM ezorder WHERE ' . eZOrder::getShowOrdersQuery( $show ) . ' AND is_temporary=\'0\'';
00304 $countArray = $db->arrayQuery( $query );
00305 return isset( $countArray[0]['count'] ) ? $countArray[0]['count'] : 0;
00306 }
00307
00308
00309
00310
00311
00312 function &orderStatistics( $year = false, $month = false )
00313 {
00314 if ( $year == false )
00315 {
00316 $startDate = 0;
00317 $stopDate = mktime( 0, 0, 0, 12, 31, 2037 );
00318 }
00319 else if ( $year != false and $month == false )
00320 {
00321 $nextYear = $year + 1;
00322 $startDate = mktime( 0, 0, 0, 1, 1, $year );
00323 $stopDate = mktime( 0, 0, 0, 1, 1, $nextYear );
00324 }
00325 else if ( $year != false and $month != false )
00326 {
00327 $nextMonth = $month + 1;
00328 $startDate = mktime( 0, 0, 0, $month, 1, $year );
00329 $stopDate = mktime( 23, 59, 59, $nextMonth, 0, $year );
00330 }
00331
00332 $db =& eZDB::instance();
00333 $productArray = $db->arrayQuery( "SELECT ezproductcollection_item.*, ignore_vat, ezorder.created, currency_code FROM ezorder, ezproductcollection_item, ezproductcollection
00334 WHERE ezproductcollection.id=ezproductcollection_item.productcollection_id
00335 AND ezproductcollection_item.productcollection_id=ezorder.productcollection_id
00336 AND is_temporary='0'
00337 AND ezorder.created >= '$startDate' AND ezorder.created < '$stopDate'
00338 ORDER BY contentobject_id, currency_code" );
00339 $currentContentObjectID = 0;
00340 $productItemArray = array();
00341 $statisticArray = array();
00342 $productObject = null;
00343 $itemCount = 0;
00344 $totalSumIncVAT = array();
00345 $totalSumExVAT = array();
00346 $name = false;
00347 $productCount = count( $productArray );
00348 $productInfo = array();
00349 $totalSumInfo = array();
00350 foreach( $productArray as $productItem )
00351 {
00352 $itemCount++;
00353 $contentObjectID = $productItem['contentobject_id'];
00354
00355 if ( $productObject == null )
00356 {
00357 $productObject =& eZContentObject::fetch( $contentObjectID );
00358 $currentContentObjectID = $contentObjectID;
00359 }
00360
00361 if ( $currentContentObjectID != $contentObjectID && $itemCount != 1 )
00362 {
00363 $productItemArray[] = array( 'name' => $name,
00364 'product' => $productObject,
00365 'product_info' => $productInfo );
00366 $productInfo = array();
00367 unset( $productObject );
00368 $name = $productItem['name'];
00369 $currentContentObjectID = $contentObjectID;
00370 $productObject =& eZContentObject::fetch( $currentContentObjectID );
00371 }
00372
00373 $currencyCode = $productItem['currency_code'];
00374 if ( $currencyCode == '' )
00375 {
00376 $currencyCode = eZOrder::fetchLocaleCurrencyCode();
00377 }
00378
00379 if ( !isset( $productInfo[$currencyCode] ) )
00380 {
00381 $productInfo[$currencyCode] = array( 'sum_count' => 0,
00382 'sum_ex_vat' => 0,
00383 'sum_inc_vat' => 0 );
00384 }
00385 if ( !isset( $totalSumInfo[$currencyCode] ) )
00386 {
00387 $totalSumInfo[$currencyCode] = array( 'sum_ex_vat' => 0,
00388 'sum_inc_vat' => 0 );
00389 }
00390
00391 if ( !isset( $totalSumIncVAT[$currencyCode] ) )
00392 $totalSumIncVAT[$currencyCode] = 0;
00393
00394 if ( !isset( $totalSumExVAT[$currencyCode] ) )
00395 $totalSumExVAT[$currencyCode] = 0;
00396
00397 if ( $productItem['ignore_vat']== true )
00398 {
00399 $vatValue = 0;
00400 }
00401 else
00402 {
00403 $vatValue = $productItem['vat_value'];
00404 }
00405
00406 $count = $productItem['item_count'];
00407 $discountPercent = $productItem['discount'];
00408
00409 $isVATIncluded = $productItem['is_vat_inc'];
00410 $price = $productItem['price'];
00411
00412 if ( $isVATIncluded )
00413 {
00414 $priceExVAT = $price / ( 100 + $vatValue ) * 100;
00415 $priceIncVAT = $price;
00416 $totalPriceExVAT = $count * $priceExVAT * ( 100 - $discountPercent ) / 100;
00417 $totalPriceIncVAT = $count * $priceIncVAT * ( 100 - $discountPercent ) / 100 ;
00418 $totalPriceExVAT = round( $totalPriceExVAT, 2 );
00419 $totalPriceIncVAT = round( $totalPriceIncVAT, 2 );
00420 $totalSumInfo[$currencyCode]['sum_ex_vat'] += $totalPriceExVAT;
00421 $totalSumInfo[$currencyCode]['sum_inc_vat'] += $totalPriceIncVAT;
00422 }
00423 else
00424 {
00425 $priceExVAT = $price;
00426 $priceIncVAT = $price * ( 100 + $vatValue ) / 100;
00427 $totalPriceExVAT = $count * $priceExVAT * ( 100 - $discountPercent ) / 100;
00428 $totalPriceIncVAT = $count * $priceIncVAT * ( 100 - $discountPercent ) / 100 ;
00429 $totalPriceExVAT = round( $totalPriceExVAT, 2 );
00430 $totalPriceIncVAT = round( $totalPriceIncVAT, 2 );
00431 $totalSumInfo[$currencyCode]['sum_ex_vat'] += $totalPriceExVAT;
00432 $totalSumInfo[$currencyCode]['sum_inc_vat'] += $totalPriceIncVAT;
00433 }
00434
00435 $productInfo[$currencyCode]['sum_count'] += $count;
00436 $productInfo[$currencyCode]['sum_ex_vat'] += $totalPriceExVAT;
00437 $productInfo[$currencyCode]['sum_inc_vat'] += $totalPriceIncVAT;
00438 }
00439
00440
00441 if ( $productCount != 0 )
00442 $productItemArray[] = array( 'name' => $name,
00443 'product' => $productObject,
00444 'product_info' => $productInfo );
00445
00446 $statisticArray[] = array( 'product_list' => $productItemArray,
00447 'total_sum_info' => $totalSumInfo );
00448 return $statisticArray;
00449 }
00450
00451
00452
00453
00454 function &orderList( $CustomID, $Email )
00455 {
00456 $db =& eZDB::instance();
00457 $CustomID =(int) $CustomID;
00458 $Email = $db->escapeString( $Email );
00459 if ( $Email == false )
00460 {
00461 $orderArray = $db->arrayQuery( "SELECT ezorder.* FROM ezorder
00462 WHERE user_id='$CustomID'
00463 AND is_archived='0'
00464 AND is_temporary='0'
00465 ORDER BY order_nr" );
00466 }
00467 else
00468 {
00469 $orderArray = $db->arrayQuery( "SELECT ezorder.* FROM ezorder
00470 WHERE user_id='$CustomID'
00471 AND is_archived='0'
00472 AND is_temporary='0'
00473 AND email='$Email'
00474 ORDER BY order_nr" );
00475 }
00476 $retOrders = array();
00477 for( $i=0; $i < count( $orderArray ); $i++ )
00478 {
00479 $order =& $orderArray[$i];
00480 $order = new eZOrder( $order );
00481 $retOrders[] = $order;
00482 }
00483 return $retOrders;
00484 }
00485
00486
00487
00488
00489 function &productList( $CustomID, $Email )
00490 {
00491 $db =& eZDB::instance();
00492 $CustomID =(int) $CustomID;
00493 $Email = $db->escapeString( $Email );
00494 if ( $Email == false )
00495 {
00496 $productArray = $db->arrayQuery( "SELECT ezproductcollection_item.*, ignore_vat, currency_code FROM ezorder, ezproductcollection_item, ezproductcollection
00497 WHERE ezproductcollection.id=ezproductcollection_item.productcollection_id
00498 AND ezproductcollection_item.productcollection_id=ezorder.productcollection_id
00499 AND user_id='$CustomID'
00500 AND is_archived='0'
00501 AND is_temporary='0'
00502 ORDER BY contentobject_id, currency_code" );
00503 }
00504 else
00505 {
00506 $productArray = $db->arrayQuery( "SELECT ezproductcollection_item.*, ignore_vat, currency_code FROM ezorder, ezproductcollection_item, ezproductcollection
00507 WHERE ezproductcollection.id=ezproductcollection_item.productcollection_id
00508 AND ezproductcollection_item.productcollection_id=ezorder.productcollection_id
00509 AND user_id='$CustomID'
00510 AND is_archived='0'
00511 AND is_temporary='0'
00512 AND email='$Email'
00513 ORDER BY contentobject_id, currency_code" );
00514 }
00515 $currentContentObjectID = 0;
00516 $productItemArray = array();
00517 $productObject = null;
00518 $itemCount = 0;
00519 $name = false;
00520 $productInfo = array();
00521
00522 for( $i=0; $i < count( $productArray ); $i++ )
00523 {
00524 $productItem =& $productArray[$i];
00525 $itemCount++;
00526 $contentObjectID = $productItem['contentobject_id'];
00527 if ( $productObject == null )
00528 {
00529 if ( $contentObjectID != 0 )
00530 {
00531 $productObject =& eZContentObject::fetch( $contentObjectID );
00532 }
00533 else
00534 {
00535 $productObject = null;
00536 $name = $productItem['name'];
00537 }
00538 $currentContentObjectID = $contentObjectID;
00539 }
00540 if ( $currentContentObjectID != $contentObjectID && $itemCount != 1 )
00541 {
00542 $productItemArray[] = array( 'name' => $name,
00543 'product' => $productObject,
00544 'product_info' => $productInfo );
00545 unset( $productObject );
00546 $productInfo = array();
00547 $name = $productItem['name'];
00548 $currentContentObjectID = $contentObjectID;
00549 if ( $contentObjectID != 0 )
00550 {
00551 $productObject =& eZContentObject::fetch( $currentContentObjectID );
00552 }
00553 else
00554 {
00555 $productObject = null;
00556 }
00557 }
00558
00559 $currencyCode = $productItem['currency_code'];
00560 if ( $currencyCode == '' )
00561 {
00562 $currencyCode = eZOrder::fetchLocaleCurrencyCode();
00563 }
00564
00565 if ( !isset( $productInfo[$currencyCode] ) )
00566 {
00567 $productInfo[$currencyCode] = array( 'sum_count' => 0,
00568 'sum_ex_vat' => 0,
00569 'sum_inc_vat' => 0 );
00570 }
00571
00572 if ( $productItem['ignore_vat'] == true )
00573 {
00574 $vatValue = 0;
00575 }
00576 else
00577 {
00578 $vatValue = $productItem['vat_value'];
00579 }
00580
00581 $count = $productItem['item_count'];
00582 $discountPercent = $productItem['discount'];
00583
00584 $isVATIncluded = $productItem['is_vat_inc'];
00585 $price = $productItem['price'];
00586
00587 if ( $isVATIncluded )
00588 {
00589 $priceExVAT = $price / ( 100 + $vatValue ) * 100;
00590 $priceIncVAT = $price;
00591 $totalPriceExVAT = $count * $priceExVAT * ( 100 - $discountPercent ) / 100;
00592 $totalPriceIncVAT = $count * $priceIncVAT * ( 100 - $discountPercent ) / 100 ;
00593 $totalPriceExVAT = round( $totalPriceExVAT, 2 );
00594 $totalPriceIncVAT = round( $totalPriceIncVAT, 2 );
00595 }
00596 else
00597 {
00598 $priceExVAT = $price;
00599 $priceIncVAT = $price * ( 100 + $vatValue ) / 100;
00600 $totalPriceExVAT = $count * $priceExVAT * ( 100 - $discountPercent ) / 100;
00601 $totalPriceIncVAT = $count * $priceIncVAT * ( 100 - $discountPercent ) / 100 ;
00602 $totalPriceExVAT = round( $totalPriceExVAT, 2 );
00603 $totalPriceIncVAT = round( $totalPriceIncVAT, 2 );
00604 }
00605
00606 $productInfo[$currencyCode]['sum_count'] += $count;
00607 $productInfo[$currencyCode]['sum_ex_vat'] += $totalPriceExVAT;
00608 $productInfo[$currencyCode]['sum_inc_vat'] += $totalPriceIncVAT;
00609 }
00610 if ( count( $productArray ) != 0 )
00611 {
00612 $productItemArray[] = array( 'name' => $name,
00613 'product' => $productObject,
00614 'product_info' => $productInfo );
00615 }
00616 return $productItemArray;
00617 }
00618
00619
00620
00621
00622 function &customerCount( )
00623 {
00624 $db =& eZDB::instance();
00625 $countArray = $db->arrayQuery( "SELECT count( DISTINCT email) AS count FROM ezorder WHERE is_temporary='0'" );
00626 $count = $countArray[0]['count'];
00627 return $count;
00628 }
00629
00630
00631
00632
00633 function &customerList( $offset, $limit )
00634 {
00635 $db =& eZDB::instance();
00636
00637 $db_params = array();
00638 $db_params["offset"] =(int) $offset;
00639 $db_params["limit"] =(int) $limit;
00640
00641 $customEmailResult = $db->arrayQuery( "SELECT DISTINCT email FROM ezorder WHERE is_temporary='0' ORDER BY email", $db_params );
00642 $customEmailArray = array();
00643
00644 foreach( $customEmailResult as $customEmailRow )
00645 {
00646 $customEmail = $customEmailRow['email'];
00647 $customEmailArray[] = "'" . $customEmail . "'";
00648 }
00649
00650 $emailString = implode( ", ", $customEmailArray );
00651 if ( !strlen( $emailString ) )
00652 {
00653 $emailString = "''";
00654 }
00655
00656 $productItemArray = $db->arrayQuery( "SELECT ezorder.id as order_id, user_id, email, ignore_vat, currency_code, ezproductcollection_item.*
00657 FROM ezorder, ezproductcollection_item, ezproductcollection
00658 WHERE ezproductcollection_item.productcollection_id=ezorder.productcollection_id
00659 AND is_temporary='0'
00660 AND ezproductcollection_item.productcollection_id=ezproductcollection.id
00661 AND email in ( $emailString )
00662 ORDER BY user_id, email, order_id" );
00663
00664
00665 $siteIni =& eZINI::instance();
00666 $anonymousUserID = $siteIni->variable( 'UserSettings', 'AnonymousUserID' );
00667
00668 $currentUserID = 0;
00669 $currentOrderID = 0;
00670 $currentUserEmail = "";
00671 $customArray = array();
00672 $accountName = null;
00673 $itemCount = 0;
00674 $hash = 0;
00675 $currencyCode = '';
00676 $ordersInfo = array();
00677
00678 foreach( $productItemArray as $productItem )
00679 {
00680 $itemCount++;
00681 $currencyCode = $productItem['currency_code'];
00682 if ( $currencyCode == '' )
00683 {
00684 $currencyCode = eZOrder::fetchLocaleCurrencyCode();
00685 }
00686
00687 $userID = $productItem['user_id'];
00688 $orderID = $productItem['order_id'];
00689 $order = eZOrder::fetch( $orderID );
00690
00691 if ( $currentUserID != $userID && $itemCount != 1 )
00692 {
00693 $customArray[] = array( 'account_name' => $accountName,
00694 'orders_info' => $ordersInfo,
00695 'user_id' => $currentUserID,
00696 'email' => urlencode( $currentUserEmail ) );
00697
00698 $ordersInfo = array();
00699 $accountName =& $order->attribute( 'account_name' );
00700 $accountEmail =& $order->attribute( 'account_email' );
00701 }
00702
00703 $currentUserID = $userID;
00704
00705
00706 if ( $currentUserID == $anonymousUserID )
00707 {
00708 $accountEmail =& $order->attribute( 'email' );
00709 if ( $currentUserEmail == "" )
00710 {
00711 $accountName =& $order->attribute( 'account_name' );
00712 $currentUserEmail = $accountEmail;
00713 }
00714
00715 if ( $currentUserEmail != $accountEmail )
00716 {
00717 $customArray[] = array( 'account_name' => $accountName,
00718 'orders_info' => $ordersInfo,
00719 'user_id' => $currentUserID,
00720 'email' => urlencode( $currentUserEmail ) );
00721
00722 $ordersInfo = array();
00723 $accountName =& $order->attribute( 'account_name' );
00724 $accountEmail =& $order->attribute( 'account_email' );
00725 $currentUserEmail = $accountEmail;
00726 }
00727 $currentUserEmail = $accountEmail;
00728 }
00729 else
00730 {
00731 $currentUserEmail = 0;
00732 }
00733
00734 $accountName = $order->attribute( 'account_name' );
00735
00736 if ( !isset( $ordersInfo[$currencyCode] ) )
00737 {
00738 $ordersInfo[$currencyCode] = array( 'order_count' => 0,
00739 'sum_ex_vat' => 0,
00740 'sum_inc_vat' => 0 );
00741 }
00742
00743 if ( $currentOrderID != $orderID )
00744 {
00745 $ordersInfo[$currencyCode]['order_count']++;
00746 }
00747 $currentOrderID = $orderID;
00748
00749 if ( $productItem['ignore_vat'] == true )
00750 {
00751 $vatValue = 0;
00752 }
00753 else
00754 {
00755 $vatValue = $productItem['vat_value'];
00756 }
00757
00758 $count = $productItem['item_count'];
00759 $discountPercent = $productItem['discount'];
00760
00761 $isVATIncluded = $productItem['is_vat_inc'];
00762 $price = $productItem['price'];
00763
00764 if ( $isVATIncluded )
00765 {
00766 $priceExVAT = $price / ( 100 + $vatValue ) * 100;
00767 $priceIncVAT = $price;
00768 $totalPriceExVAT = $count * $priceExVAT * ( 100 - $discountPercent ) / 100;
00769 $totalPriceIncVAT = $count * $priceIncVAT * ( 100 - $discountPercent ) / 100 ;
00770 $totalPriceExVAT = round( $totalPriceExVAT, 2 );
00771 $totalPriceIncVAT = round( $totalPriceIncVAT, 2 );
00772 }
00773 else
00774 {
00775 $priceExVAT = $price;
00776 $priceIncVAT = $price * ( 100 + $vatValue ) / 100;
00777 $totalPriceExVAT = $count * $priceExVAT * ( 100 - $discountPercent ) / 100;
00778 $totalPriceIncVAT = $count * $priceIncVAT * ( 100 - $discountPercent ) / 100 ;
00779 $totalPriceExVAT = round( $totalPriceExVAT, 2 );
00780 $totalPriceIncVAT = round( $totalPriceIncVAT, 2 );
00781 }
00782
00783 $ordersInfo[$currencyCode]['sum_ex_vat'] += $totalPriceExVAT;
00784 $ordersInfo[$currencyCode]['sum_inc_vat'] += $totalPriceIncVAT;
00785 }
00786 if ( count( $productItemArray ) != 0 )
00787 $customArray[] = array( 'account_name' => $accountName,
00788 'orders_info' => $ordersInfo,
00789 'user_id' => $currentUserID,
00790 'email' => urlencode( $currentUserEmail ) );
00791 return $customArray;
00792 }
00793
00794
00795
00796
00797 function discount( $userID, &$object )
00798 {
00799 include_once( 'kernel/classes/ezdiscount.php' );
00800
00801 $user = eZUser::fetch( $userID );
00802 $bestMatch = eZDiscount::discountPersent( $user, array( 'contentclass_id' => $object->attribute( 'contentclass_id'),
00803 'contentobject_id' => $object->attribute( 'id' ),
00804 'section_id' => $object->attribute( 'section_id') ) );
00805 return $bestMatch;
00806 }
00807
00808 function &productItems( $asObject=true )
00809 {
00810 $productItems = eZPersistentObject::fetchObjectList( eZProductCollectionItem::definition(),
00811 null, array( "productcollection_id" => $this->ProductCollectionID
00812 ),
00813 null,
00814 null,
00815 $asObject );
00816
00817 $addedProducts = array();
00818 foreach ( $productItems as $productItem )
00819 {
00820 $discountPercent = 0.0;
00821 $isVATIncluded = true;
00822 $id =& $productItem->attribute( 'id' );
00823 $contentObject =& $productItem->attribute( 'contentobject' );
00824
00825 if ( $this->IgnoreVAT == true )
00826 {
00827 $vatValue = 0;
00828 }
00829 else
00830 {
00831 $vatValue =& $productItem->attribute( 'vat_value' );
00832 }
00833 $count =& $productItem->attribute( 'item_count' );
00834 $discountPercent =& $productItem->attribute( 'discount' );
00835 if ( $contentObject )
00836 {
00837 $nodeID =& $contentObject->attribute( 'main_node_id' );
00838 $objectName =& $contentObject->attribute( 'name' );
00839 }
00840 else
00841 {
00842 $nodeID = false;
00843 $objectName =& $productItem->attribute( 'name' );
00844 }
00845
00846 $isVATIncluded =& $productItem->attribute( 'is_vat_inc' );
00847 $price =& $productItem->attribute( 'price' );
00848
00849 if ( $isVATIncluded )
00850 {
00851 $priceExVAT = $price / ( 100 + $vatValue ) * 100;
00852 $priceIncVAT = $price;
00853 $totalPriceExVAT = $count * $priceExVAT * ( 100 - $discountPercent ) / 100;
00854 $totalPriceIncVAT = $count * $priceIncVAT * ( 100 - $discountPercent ) / 100 ;
00855 $totalPriceExVAT = round( $totalPriceExVAT, 2 );
00856 $totalPriceIncVAT = round( $totalPriceIncVAT, 2 );
00857 }
00858 else
00859 {
00860 $priceExVAT = $price;
00861 $priceIncVAT = $price * ( 100 + $vatValue ) / 100;
00862 $totalPriceExVAT = $count * $priceExVAT * ( 100 - $discountPercent ) / 100;
00863 $totalPriceIncVAT = $count * $priceIncVAT * ( 100 - $discountPercent ) / 100 ;
00864 $totalPriceExVAT = round( $totalPriceExVAT, 2 );
00865 $totalPriceIncVAT = round( $totalPriceIncVAT, 2 );
00866 }
00867
00868 $addedProduct = array( "id" => $id,
00869 "vat_value" => $vatValue,
00870 "item_count" => $count,
00871 "node_id" => $nodeID,
00872 "object_name" => $objectName,
00873 "price_ex_vat" => $priceExVAT,
00874 "price_inc_vat" => $priceIncVAT,
00875 "discount_percent" => $discountPercent,
00876 "total_price_ex_vat" => $totalPriceExVAT,
00877 "total_price_inc_vat" => $totalPriceIncVAT,
00878 'item_object' => $productItem );
00879 $addedProducts[] = $addedProduct;
00880 }
00881 return $addedProducts;
00882 }
00883
00884 function &productTotalIncVAT()
00885 {
00886 $items =& $this->productItems();
00887
00888 $total = 0.0;
00889 foreach ( $items as $item )
00890 {
00891 $total += $item['total_price_inc_vat'];
00892 }
00893 $total = round( $total, 2 );
00894 return $total;
00895 }
00896
00897 function &productTotalExVAT()
00898 {
00899 $items =& $this->productItems();
00900
00901 $total = 0.0;
00902 foreach ( $items as $item )
00903 {
00904 $total += $item['total_price_ex_vat'];
00905 }
00906 $total = round( $total, 2 );
00907 return $total;
00908 }
00909
00910 function orderTotalIncVAT()
00911 {
00912 $items =& $this->orderItems();
00913
00914 $total = 0.0;
00915 if ( count( $items ) > 0 )
00916 {
00917 foreach ( $items as $item )
00918 {
00919 $total += $item->attribute( 'price_inc_vat' );
00920 }
00921 }
00922 $total = round( $total, 2 );
00923 return $total;
00924 }
00925
00926 function orderTotalExVAT()
00927 {
00928 $items =& $this->orderItems();
00929
00930 $total = 0.0;
00931 if ( count( $items ) > 0 )
00932 {
00933 foreach ( $items as $item )
00934 {
00935 $total += $item->attribute( 'price_ex_vat' );
00936 }
00937 }
00938 $total = round( $total, 2 );
00939 return $total;
00940 }
00941
00942 function &totalIncVAT()
00943 {
00944 $totalIncVAT = $this->productTotalIncVAT() + $this->orderTotalIncVAT();
00945 return $totalIncVAT;
00946 }
00947
00948 function &totalExVAT()
00949 {
00950 $totalExVAT = $this->productTotalExVAT() + $this->orderTotalExVAT();
00951 return $totalExVAT;
00952 }
00953
00954
00955
00956
00957
00958
00959
00960
00961
00962
00963
00964
00965 function purge( $removeCollection = true )
00966 {
00967 $db =& eZDB::instance();
00968 $db->begin();
00969 if ( $removeCollection )
00970 $this->removeCollection();
00971 $this->removeHistory();
00972 $this->removeOrderItems();
00973 $this->remove();
00974 $db->commit();
00975 }
00976
00977
00978
00979
00980
00981
00982 function removeCollection()
00983 {
00984 $collection = eZProductCollection::fetch( $this->attribute( 'productcollection_id' ) );
00985 $collection->remove();
00986 }
00987
00988
00989
00990
00991
00992 function removeHistory()
00993 {
00994 $db =& eZDB::instance();
00995 $orderID = (int)$this->OrderNr;
00996 $db->query( "DELETE FROM ezorder_status_history WHERE order_id=$orderID" );
00997 }
00998
00999 function removeOrderItems()
01000 {
01001 $db =& eZDB::instance();
01002 $orderID = (int) $this->ID;
01003 $db->query( "DELETE FROM ezorder_item WHERE order_id=$orderID" );
01004 }
01005
01006
01007
01008
01009
01010
01011 function removeItem( $itemID )
01012 {
01013 $item = eZProductCollectionItem::fetch( $itemID );
01014 $item->remove();
01015 }
01016
01017
01018
01019
01020 function &totalVAT()
01021 {
01022 $retValue = false;
01023 return $retValue;
01024 }
01025
01026 function &orderItems()
01027 {
01028 $id =& $this->attribute( 'id' );
01029 $items = eZOrderItem::fetchList( $id );
01030 return $items;
01031 }
01032
01033
01034
01035
01036 function &orderItemsByType( $itemType )
01037 {
01038 $items = eZOrderItem::fetchListByType( $this->ID, $itemType );
01039 return $items;
01040 }
01041
01042
01043
01044
01045 function &user()
01046 {
01047 $user = eZUser::fetch( $this->UserID );
01048 return $user;
01049 }
01050
01051
01052
01053
01054
01055 function &accountInformation()
01056 {
01057
01058 include_once( 'kernel/classes/ezshopaccounthandler.php' );
01059 $accountHandler =& eZShopAccountHandler::instance();
01060 $accountInformation = $accountHandler->accountInformation( $this );
01061 return $accountInformation;
01062 }
01063
01064
01065
01066
01067
01068
01069 function &accountName()
01070 {
01071
01072 include_once( 'kernel/classes/ezshopaccounthandler.php' );
01073 $accountHandler =& eZShopAccountHandler::instance();
01074
01075 $accountName = $accountHandler->accountName( $this );
01076 return $accountName;
01077 }
01078
01079
01080
01081
01082
01083 function &accountEmail()
01084 {
01085
01086 include_once( 'kernel/classes/ezshopaccounthandler.php' );
01087 $accountHandler =& eZShopAccountHandler::instance();
01088
01089 $email = $accountHandler->email( $this );
01090 return $email;
01091 }
01092
01093
01094
01095
01096 function status( $asObject = false )
01097 {
01098 if ( $asObject )
01099 return eZOrderStatus::fetch( $this->StatusID );
01100 else
01101 return $this->StatusID;
01102 }
01103
01104
01105
01106
01107 function canModifyStatus( $statusID, $user = false )
01108 {
01109 if ( $user === false )
01110 $user =& eZUser::currentUser();
01111 else if ( is_numeric( $user ) )
01112 $user = eZUser::fetch( $user );
01113
01114 if ( !is_object( $user ) )
01115 {
01116 eZDebug::writeError( "Cannot check status access without a user", 'eZOrder::canModifyStatus' );
01117 return false;
01118 }
01119
01120 $accessResult = $user->hasAccessTo( 'shop' , 'setstatus' );
01121 $accessWord = $accessResult['accessWord'];
01122 $access = false;
01123
01124 $currentStatusID =& $this->attribute( "status_id" );
01125
01126 if ( $accessWord == 'yes' )
01127 $access = true;
01128
01129 if ( $accessWord == 'limited' )
01130 {
01131 $limitationList =& $accessResult['policies'];
01132 $access = true;
01133 foreach ( $limitationList as $pid => $limit )
01134 {
01135 $access = true;
01136 foreach ( $limit as $name => $value )
01137 {
01138 if ( $name == 'FromStatus' )
01139 {
01140 if ( !in_array( $currentStatusID, $value ) )
01141 $access = false;
01142 }
01143 if ( $name == 'ToStatus' )
01144 {
01145 if ( !in_array( $statusID, $value ) )
01146 $access = false;
01147 }
01148 if ( !$access )
01149 break;
01150 }
01151 if ( $access )
01152 break;
01153 }
01154 }
01155 return $access;
01156 }
01157
01158
01159
01160
01161
01162
01163 function &statusModificationList( $user = false )
01164 {
01165 if ( $user === false )
01166 $user =& eZUser::currentUser();
01167 else if ( is_numeric( $user ) )
01168 $user = eZUser::fetch( $user );
01169
01170 if ( !is_object( $user ) )
01171 {
01172 eZDebug::writeError( "Cannot calculate status access list without a user", 'eZOrder::canModifyStatus' );
01173 $retValue = false;
01174 return $retValue;
01175 }
01176
01177 $accessResult = $user->hasAccessTo( 'shop' , 'setstatus' );
01178 $accessWord = $accessResult['accessWord'];
01179 $access = false;
01180
01181 $currentStatusID =& $this->attribute( "status_id" );
01182
01183 $statusList = array();
01184 if ( $accessWord == 'yes' )
01185 {
01186
01187 include_once( 'kernel/classes/ezorderstatus.php' );
01188 $statusList = eZOrderStatus::fetchOrderedList( true, false );
01189 return $statusList;
01190 }
01191
01192 if ( $accessWord == 'limited' )
01193 {
01194 $limitationList =& $accessResult['policies'];
01195 $access = true;
01196
01197 $accessList = array();
01198 foreach ( $limitationList as $pid => $limit )
01199 {
01200 $access = true;
01201 foreach ( $limit as $name => $value )
01202 {
01203 if ( $name == 'FromStatus' )
01204 {
01205 if ( !in_array( $currentStatusID, $value ) )
01206 $access = false;
01207 }
01208 if ( !$access )
01209 break;
01210 }
01211 if ( $access )
01212 {
01213 if ( isset( $limit['ToStatus'] ) )
01214 {
01215 $accessList = array_merge( $accessList, $limit['ToStatus'] );
01216 }
01217 else
01218 {
01219
01220 include_once( 'kernel/classes/ezorderstatus.php' );
01221 $statusList = eZOrderStatus::fetchOrderedList( true, false );
01222 return $statusList;
01223 }
01224 }
01225 }
01226 if ( count( $accessList ) > 0 )
01227 {
01228 $accessList = array_unique( array_merge( $accessList, array( $currentStatusID ) ) );
01229 include_once( 'kernel/classes/ezorderstatus.php' );
01230 $statuses = eZOrderStatus::fetchOrderedList( true, false );
01231 foreach ( $statuses as $status )
01232 {
01233 if ( in_array( $status->attribute( 'status_id' ), $accessList ) )
01234 $statusList[] = $status;
01235 }
01236 }
01237 }
01238 return $statusList;
01239 }
01240
01241
01242
01243
01244
01245
01246
01247
01248
01249
01250 function modifyStatus( $statusID, $userID = false )
01251 {
01252 $db =& eZDB::instance();
01253 $db->begin();
01254
01255 $time = mktime();
01256 if ( $userID === false )
01257 $userID = eZUser::currentUserID();
01258
01259 include_once( 'kernel/classes/ezorderstatushistory.php' );
01260 $history = eZOrderStatusHistory::create( $this->OrderNr, $statusID, $userID, $time );
01261 $history->store();
01262
01263 $this->StatusID = $statusID;
01264 $this->StatusModified = $time;
01265 $this->StatusModifierID = $userID;
01266
01267 $this->store();
01268
01269 $db->commit();
01270 }
01271
01272
01273
01274
01275
01276
01277
01278
01279 function createStatusHistory()
01280 {
01281 include_once( 'kernel/classes/ezorderstatushistory.php' );
01282 $history = eZOrderStatusHistory::create( $this->OrderNr,
01283 $this->StatusID,
01284 $this->StatusModifierID,
01285 $this->StatusModified );
01286 $history->store();
01287 return $history;
01288 }
01289
01290
01291
01292
01293
01294 function setStatus( $status )
01295 {
01296 if ( get_class( $status ) == "ezorderstatus" )
01297 $this->StatusID =& $status->attribute( 'id' );
01298 else
01299 $this->StatusID = $status;
01300 $this->setStatusModified( mktime() );
01301 }
01302
01303
01304
01305
01306 function setStatusModified( $timestamp )
01307 {
01308 $this->StatusModified = $timestamp;
01309 }
01310
01311
01312
01313
01314
01315
01316 function &statusName()
01317 {
01318 if ( $this->Status === null )
01319 {
01320 include_once( 'kernel/classes/ezorderstatus.php' );
01321 $this->Status = eZOrderStatus::fetchByStatus( $this->StatusID );
01322 }
01323 $name =& $this->Status->attribute( 'name' );
01324 return $name;
01325 }
01326
01327
01328
01329
01330
01331
01332 function &statusObject()
01333 {
01334 if ( $this->Status === null )
01335 {
01336 include_once( 'kernel/classes/ezorderstatus.php' );
01337 $this->Status = eZOrderStatus::fetchByStatus( $this->StatusID );
01338 }
01339 return $this->Status;
01340 }
01341
01342
01343
01344
01345
01346
01347
01348
01349
01350
01351
01352
01353
01354
01355
01356
01357
01358
01359
01360
01361
01362
01363
01364 function activate()
01365 {
01366 $db =& eZDB::instance();
01367 $db->lock( 'ezorder' );
01368
01369 $this->setAttribute( 'is_temporary', 0 );
01370 $nextIDArray = $db->arrayQuery( "SELECT ( max( order_nr ) + 1 ) AS next_nr FROM ezorder" );
01371 $nextID = $nextIDArray[0]['next_nr'];
01372 $this->setAttribute( 'order_nr', $nextID );
01373 $this->store();
01374
01375 $db->unlock();
01376
01377
01378 $this->createStatusHistory();
01379 }
01380
01381
01382
01383
01384 function &accountViewTemplate()
01385 {
01386 return $this->AccountIdentifier;
01387 }
01388
01389
01390
01391
01392
01393
01394
01395 function cleanupOrder( $orderID )
01396 {
01397 $db =& eZDB::instance();
01398 $orderID =(int) $orderID;
01399 $rows = $db->arrayQuery( "SELECT productcollection_id, order_nr FROM ezorder WHERE id='$orderID'" );
01400 if ( count( $rows ) > 0 )
01401 {
01402
01403 include_once( "kernel/classes/ezaudit.php" );
01404 eZAudit::writeAudit( 'order-delete', array( 'Order ID' => $orderID,
01405 'Comment' => 'Removed the order and its related data from the database: eZOrder::cleanupOrder()' ) );
01406
01407 $productCollectionID = $rows[0]['productcollection_id'];
01408 $orderNr = (int)$rows[0]['order_nr'];
01409 $db =& eZDB::instance();
01410 $db->begin();
01411 $db->query( "DELETE FROM ezorder where id='$orderID'" );
01412 $db->query( "DELETE FROM ezproductcollection where id='$productCollectionID'" );
01413 $db->query( "DELETE FROM ezproductcollection_item where productcollection_id='$productCollectionID'" );
01414 $db->query( "DELETE FROM ezorder_status_history WHERE order_id=$orderNr" );
01415 $db->commit();
01416 }
01417 }
01418
01419
01420
01421
01422
01423
01424
01425 function archiveOrder( $orderID )
01426 {
01427 $db =& eZDB::instance();
01428 $orderID =(int) $orderID;
01429 $db->query( "UPDATE ezorder SET is_archived='1' WHERE id='$orderID' " );
01430 }
01431
01432
01433
01434
01435
01436
01437
01438 function unArchiveOrder( $orderID )
01439 {
01440 $db =& eZDB::instance();
01441 $orderID =(int) $orderID;
01442 $db->query( "UPDATE ezorder SET is_archived='0' WHERE id='$orderID' " );
01443 }
01444
01445
01446
01447
01448
01449
01450
01451 function cleanup()
01452 {
01453 $db =& eZDB::instance();
01454 $rows = $db->arrayQuery( "SELECT productcollection_id FROM ezorder" );
01455
01456 $db =& eZDB::instance();
01457 $db->begin();
01458 if ( count( $rows ) > 0 )
01459 {
01460 $productCollectionIDList = array();
01461 foreach ( $rows as $row )
01462 {
01463 $productCollectionIDList[] = $row['productcollection_id'];
01464 }
01465 eZProductCollection::cleanupList( $productCollectionIDList );
01466 }
01467
01468 include_once( "kernel/classes/ezaudit.php" );
01469 eZAudit::writeAudit( 'order-delete', array( 'Comment' => 'Removed all orders from the database: eZOrder::cleanup()' ) );
01470
01471 include_once( 'kernel/classes/ezorderitem.php' );
01472 eZOrderItem::cleanup();
01473 $db->query( "DELETE FROM ezorder_status_history" );
01474 $db->query( "DELETE FROM ezorder" );
01475 $db->commit();
01476 }
01477
01478 function &orderInfo()
01479 {
01480 $returnArray = array();
01481
01482 $items =& $this->productItems();
01483 foreach ( $items as $item )
01484 {
01485 $totalPriceExVat = $item['total_price_ex_vat'];
01486 $totalPriceIncVat = $item['total_price_inc_vat'];
01487 $totalPriceVat = $totalPriceIncVat - $totalPriceExVat;
01488 $vatValue = $item['vat_value'];
01489 if ( !isset( $returnArray['price_info']['items'][$vatValue]['total_price_ex_vat'] ) )
01490 {
01491 $returnArray['price_info']['items'][$vatValue]['total_price_ex_vat'] = $totalPriceExVat;
01492 $returnArray['price_info']['items'][$vatValue]['total_price_inc_vat'] = $totalPriceIncVat;
01493 $returnArray['price_info']['items'][$vatValue]['total_price_vat'] = $totalPriceVat;
01494 }
01495 else
01496 {
01497 $returnArray['price_info']['items'][$vatValue]['total_price_ex_vat'] += $totalPriceExVat;
01498 $returnArray['price_info']['items'][$vatValue]['total_price_inc_vat'] += $totalPriceIncVat;
01499 $returnArray['price_info']['items'][$vatValue]['total_price_vat'] += $totalPriceVat;
01500 }
01501
01502 if ( !isset( $returnArray['total_price_info']['total_price_ex_vat'] ) )
01503 {
01504 $returnArray['total_price_info']['total_price_ex_vat'] = $totalPriceExVat;
01505 $returnArray['total_price_info']['total_price_inc_vat'] = $totalPriceIncVat;
01506 $returnArray['total_price_info']['total_price_vat'] = $totalPriceVat;
01507 }
01508 else
01509 {
01510 $returnArray['total_price_info']['total_price_ex_vat'] += $totalPriceExVat;
01511 $returnArray['total_price_info']['total_price_inc_vat'] += $totalPriceIncVat;
01512 $returnArray['total_price_info']['total_price_vat'] += $totalPriceVat;
01513 }
01514 }
01515
01516 $orderItems =& $this->orderItems();
01517 if ( count( $orderItems ) > 0 )
01518 {
01519 foreach ( $orderItems as $orderItem )
01520 {
01521 $totalPriceExVat =& $orderItem->attribute( 'price_ex_vat' );
01522 $totalPriceIncVat =& $orderItem->attribute( 'price_inc_vat' );
01523 $totalPriceVat = $totalPriceIncVat - $totalPriceExVat;
01524 $vatValue =& $orderItem->attribute( 'vat_value' );
01525 $type =& $orderItem->attribute( 'type' );
01526
01527 if ( !isset( $returnArray['price_info']['items'][$vatValue]['total_price_ex_vat'] ) )
01528 {
01529 $returnArray['price_info']['items'][$vatValue]['total_price_ex_vat'] = $totalPriceExVat;
01530 $returnArray['price_info']['items'][$vatValue]['total_price_inc_vat'] = $totalPriceIncVat;
01531 $returnArray['price_info']['items'][$vatValue]['total_price_vat'] = $totalPriceVat;
01532 }
01533 else
01534 {
01535 $returnArray['price_info']['items'][$vatValue]['total_price_ex_vat'] += $totalPriceExVat;
01536 $returnArray['price_info']['items'][$vatValue]['total_price_inc_vat'] += $totalPriceIncVat;
01537 $returnArray['price_info']['items'][$vatValue]['total_price_vat'] += $totalPriceVat;
01538 }
01539
01540 if ( !isset( $returnArray['total_price_info']['total_price_ex_vat'] ) )
01541 {
01542 $returnArray['total_price_info']['total_price_ex_vat'] = $totalPriceExVat;
01543 $returnArray['total_price_info']['total_price_inc_vat'] = $totalPriceIncVat;
01544 $returnArray['total_price_info']['total_price_vat'] = $totalPriceVat;
01545 }
01546 else
01547 {
01548 $returnArray['total_price_info']['total_price_ex_vat'] += $totalPriceExVat;
01549 $returnArray['total_price_info']['total_price_inc_vat'] += $totalPriceIncVat;
01550 $returnArray['total_price_info']['total_price_vat'] += $totalPriceVat;
01551 }
01552
01553 if ( !isset( $returnArray['additional_info'][$type]['items'][$vatValue]['total_price_ex_vat'] ) )
01554 {
01555 $returnArray['additional_info'][$type]['items'][$vatValue]['total_price_ex_vat'] = $totalPriceExVat;
01556 $returnArray['additional_info'][$type]['items'][$vatValue]['total_price_inc_vat'] = $totalPriceIncVat;
01557 $returnArray['additional_info'][$type]['items'][$vatValue]['total_price_vat'] = $totalPriceVat;
01558 }
01559 else
01560 {
01561 $returnArray['additional_info'][$type]['items'][$vatValue]['total_price_ex_vat'] += $totalPriceExVat;
01562 $returnArray['additional_info'][$type]['items'][$vatValue]['total_price_inc_vat'] += $totalPriceIncVat;
01563 $returnArray['additional_info'][$type]['items'][$vatValue]['total_price_vat'] += $totalPriceVat;
01564 }
01565
01566 if ( !isset( $returnArray['additional_info'][$type]['total']['total_price_ex_vat'] ) )
01567 {
01568 $returnArray['additional_info'][$type]['total']['total_price_ex_vat'] = $totalPriceExVat;
01569 $returnArray['additional_info'][$type]['total']['total_price_inc_vat'] = $totalPriceIncVat;
01570 $returnArray['additional_info'][$type]['total']['total_price_vat'] = $totalPriceVat;
01571 }
01572 else
01573 {
01574 $returnArray['additional_info'][$type]['total']['total_price_ex_vat'] += $totalPriceExVat;
01575 $returnArray['additional_info'][$type]['total']['total_price_inc_vat'] += $totalPriceIncVat;
01576 $returnArray['additional_info'][$type]['total']['total_price_vat'] += $totalPriceVat;
01577 }
01578
01579 }
01580
01581
01582 foreach ( array_keys( $returnArray['additional_info'] ) as $type )
01583 {
01584 ksort( $returnArray['additional_info'][$type]['items'] );
01585 }
01586 }
01587 ksort( $returnArray['price_info']['items'] );
01588
01589 return $returnArray;
01590 }
01591
01592
01593
01594
01595
01596
01597
01598
01599
01600 function currencyCode( $collection = false )
01601 {
01602 if ( is_string( $collection ) and $collection != '' )
01603 {
01604 $currencyCode = $collection;
01605 }
01606 else
01607 {
01608 if ( get_class( $collection ) != 'ezproductcollection' )
01609 {
01610 $collection = eZProductCollection::fetch( $this->attribute( 'productcollection_id' ) );
01611 }
01612 $currencyCode =& $collection->attribute( 'currency_code' );
01613 }
01614
01615
01616 if ( $currencyCode == '' )
01617 {
01618 $currencyCode = eZOrder::fetchLocaleCurrencyCode();
01619 }
01620 return $currencyCode;
01621 }
01622
01623
01624
01625
01626
01627 function fetchLocaleCurrencyCode()
01628 {
01629 $locale =& eZLocale::instance();
01630 $currencyCode = $locale->currencyShortName();
01631 return $currencyCode;
01632 }
01633
01634
01635
01636 var $Status;
01637
01638 }
01639
01640 ?>