A Qcodo based CMS/ecommerce framework
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

246 lines
12 KiB

13 years ago
  1. <?php
  2. /**
  3. * This is the abstract Panel class for the List All functionality
  4. * of the Order class. This code-generated class
  5. * contains a datagrid to display an HTML page that can
  6. * list a collection of Order objects. It includes
  7. * functionality to perform pagination and sorting on columns.
  8. *
  9. * To take advantage of some (or all) of these control objects, you
  10. * must create a new QPanel which extends this OrderListPanelBase
  11. * class.
  12. *
  13. * Any and all changes to this file will be overwritten with any subsequent re-
  14. * code generation.
  15. *
  16. * @package Quasi
  17. * @subpackage Drafts
  18. *
  19. */
  20. class OrderListPanel extends QPanel
  21. {
  22. // Local instance of the Meta DataGrid to list Orders
  23. public $dtgOrders;
  24. // Other public QControls in this panel
  25. public $btnCreateNew;
  26. public $pxyViewOrder;
  27. public $pxyViewAccount;
  28. public $lblMessage;
  29. public $txtOrderNumberSearch;
  30. public $txtAccountNumberSearch;
  31. public $lstStatus;
  32. protected $intOrderStatusId = null;
  33. protected $intAccountId = null;
  34. // Callback Method Names
  35. protected $strSetEditPanelMethod;
  36. protected $strCloseEditPanelMethod;
  37. public function __construct($objParentObject, $strSetEditPanelMethod, $strCloseEditPanelMethod, $strControlId = null) {
  38. // Call the Parent
  39. try {
  40. parent::__construct($objParentObject, $strControlId);
  41. } catch (QCallerException $objExc) {
  42. $objExc->IncrementOffset();
  43. throw $objExc;
  44. }
  45. // Record Method Callbacks
  46. $this->strSetEditPanelMethod = $strSetEditPanelMethod;
  47. $this->strCloseEditPanelMethod = $strCloseEditPanelMethod;
  48. // Setup the Template
  49. $this->Template = 'OrderListPanel.tpl.php';
  50. //messages (eg. Name not found ..)
  51. $this->lblMessage = new QLabel($this);
  52. $this->txtOrderNumberSearch = new QIntegerTextBox($this);
  53. $this->txtOrderNumberSearch->AddAction(new QEnterKeyEvent(), new QServerControlAction($this, 'txtViewOrder_Click'));
  54. $this->txtOrderNumberSearch->Name = 'Order No.:';
  55. $this->txtOrderNumberSearch->Width = '5em';
  56. $this->txtOrderNumberSearch->CausesValidation = $this->txtOrderNumberSearch;
  57. $this->txtAccountNumberSearch = new QIntegerTextBox($this);
  58. $this->txtAccountNumberSearch->AddAction(new QEnterKeyEvent(), new QServerControlAction($this, 'txtViewByAccount_Click'));
  59. $this->txtAccountNumberSearch->Name = 'Account No.:';
  60. $this->txtAccountNumberSearch->Width = '5em';
  61. $this->txtAccountNumberSearch->CausesValidation = $this->txtAccountNumberSearch;
  62. $this->lstStatus = new QListBox($this, $strControlId);
  63. $this->lstStatus->Name = 'Select Status:';
  64. $this->lstStatus->AddItem(new QListItem('Any', 0));
  65. foreach (OrderStatusType::$NameArray as $intId => $strValue)
  66. $this->lstStatus->AddItem(new QListItem($strValue, $intId+1));
  67. $this->lstStatus->AddAction(new QChangeEvent(), new QAjaxControlAction($this, 'lstStatus_Selected') );
  68. // Instantiate the Meta DataGrid
  69. $this->dtgOrders = new OrderDataGrid($this);
  70. $this->dtgOrders->SetDataBinder('OrderDataBinder', $this);
  71. $this->dtgOrders->CssClass = 'datagrid';
  72. $this->dtgOrders->AlternateRowStyle->CssClass = 'alternate';
  73. $this->dtgOrders->Paginator = new QPaginator($this->dtgOrders);
  74. $this->dtgOrders->ItemsPerPage = 25;
  75. $this->pxyViewOrder = new QControlProxy($this);
  76. $this->pxyViewOrder->AddAction(new QClickEvent(), new QAjaxControlAction($this, 'pxyViewOrder_Click'));
  77. $this->pxyViewAccount = new QControlProxy($this);
  78. $this->pxyViewAccount->AddAction(new QClickEvent(), new QAjaxControlAction($this, 'pxyViewAccount_Click'));
  79. $this->dtgOrders->MetaAddProxyColumn($this->pxyViewOrder, 'Id');
  80. $this->dtgOrders->MetaAddProxyColumn($this->pxyViewAccount, QQN::Order()->Account);
  81. $this->dtgOrders->GetColumn(0)->Name = "Order Number";
  82. $this->dtgOrders->MetaAddColumn('CreationDate');
  83. $this->dtgOrders->MetaAddColumn('LastModificationDate');
  84. $this->dtgOrders->MetaAddColumn('CompletionDate');
  85. $this->dtgOrders->MetaAddColumn(QQN::Order()->ShippingMethod);
  86. $this->dtgOrders->MetaAddColumn(QQN::Order()->PaymentMethod);
  87. $this->dtgOrders->MetaAddTypeColumn('StatusId', 'OrderStatusType');
  88. $strOrderTotalParam = '<?= money_format("%n", $_ITEM->ProductTotalCharged '
  89. . ' + $_ITEM->ShippingCharged '
  90. . ' + $_ITEM->HandlingCharged '
  91. . ' + $_ITEM->Tax ) ?>';
  92. $objOrderTotalColumn = new QDataGridColumn('Order Total', $strOrderTotalParam );
  93. $this->dtgOrders->AddColumn($objOrderTotalColumn);
  94. /*
  95. $this->dtgOrders->MetaAddColumn('ShippingCost');
  96. $this->dtgOrders->MetaAddColumn('ProductTotalCost');
  97. $this->dtgOrders->MetaAddColumn('ShippingCharged');
  98. $this->dtgOrders->MetaAddColumn('HandlingCharged');
  99. $this->dtgOrders->MetaAddColumn('Tax');
  100. $this->dtgOrders->MetaAddColumn('ProductTotalCharged');
  101. $this->dtgOrders->MetaAddColumn('ShippingNamePrefix');
  102. $this->dtgOrders->MetaAddColumn('ShippingFirstName');
  103. $this->dtgOrders->MetaAddColumn('ShippingMiddleName');
  104. $this->dtgOrders->MetaAddColumn('ShippingLastName');
  105. $this->dtgOrders->MetaAddColumn('ShippingNameSuffix');
  106. $this->dtgOrders->MetaAddColumn('ShippingStreet1');
  107. $this->dtgOrders->MetaAddColumn('ShippingStreet2');
  108. $this->dtgOrders->MetaAddColumn('ShippingSuburb');
  109. $this->dtgOrders->MetaAddColumn('ShippingCounty');
  110. $this->dtgOrders->MetaAddColumn('ShippingCity');
  111. $this->dtgOrders->MetaAddTypeColumn('ShippingZoneId', 'ZoneType');
  112. $this->dtgOrders->MetaAddTypeColumn('ShippingCountryId', 'CountryType');
  113. $this->dtgOrders->MetaAddColumn('ShippingPostalCode');
  114. $this->dtgOrders->MetaAddColumn('BillingNamePrefix');
  115. $this->dtgOrders->MetaAddColumn('BillingFirstName');
  116. $this->dtgOrders->MetaAddColumn('BillingMiddleName');
  117. $this->dtgOrders->MetaAddColumn('BillingLastName');
  118. $this->dtgOrders->MetaAddColumn('BillingNameSuffix');
  119. $this->dtgOrders->MetaAddColumn('BillingStreet1');
  120. $this->dtgOrders->MetaAddColumn('BillingStreet2');
  121. $this->dtgOrders->MetaAddColumn('BillingSuburb');
  122. $this->dtgOrders->MetaAddColumn('BillingCounty');
  123. $this->dtgOrders->MetaAddColumn('BillingCity');
  124. $this->dtgOrders->MetaAddTypeColumn('BillingZoneId', 'ZoneType');
  125. $this->dtgOrders->MetaAddTypeColumn('BillingCountryId', 'CountryType');
  126. $this->dtgOrders->MetaAddColumn('BillingPostalCode');
  127. $this->dtgOrders->MetaAddColumn('Notes');
  128. */
  129. // Setup the Create New button
  130. $this->btnCreateNew = new QButton($this);
  131. $this->btnCreateNew->Text = QApplication::Translate('Create a New') . ' ' . QApplication::Translate('Order');
  132. $this->btnCreateNew->AddAction(new QClickEvent(), new QAjaxControlAction($this, 'btnCreateNew_Click'));
  133. }
  134. public function pxyViewAccount_Click($strFormId, $strControlId, $intOrderId)
  135. {
  136. $objOrder = Order::Load($intOrderId);
  137. if( $objOrder instanceof Order )
  138. {
  139. $objEditPanel = new AccountEditPanel($this, $this->strCloseEditPanelMethod, $objOrder->AccountId );
  140. $strMethodName = $this->strSetEditPanelMethod;
  141. $this->objForm->$strMethodName($objEditPanel);
  142. }
  143. }
  144. public function pxyViewOrder_Click($strFormId, $strControlId, $strParameter)
  145. {
  146. $strParameterArray = explode(',', $strParameter);
  147. $objEditPanel = new OrderEditPanel($this, $this->strCloseEditPanelMethod, $strParameterArray[0]);
  148. $strMethodName = $this->strSetEditPanelMethod;
  149. $this->objForm->$strMethodName($objEditPanel);
  150. }
  151. public function txtViewOrder_Click($strFormId, $strControlId, $strParameter)
  152. {
  153. $intOrderId = $this->txtOrderNumberSearch->Text;
  154. if(Order::Load($intOrderId))
  155. {
  156. $this->lblMessage->Text = '';
  157. $objEditPanel = new OrderEditPanel($this, $this->strCloseEditPanelMethod, $intOrderId );
  158. $strMethodName = $this->strSetEditPanelMethod;
  159. $this->objForm->$strMethodName($objEditPanel);
  160. }
  161. else
  162. $this->lblMessage->Text = 'Order ' . $intOrderId . ' not found.';
  163. }
  164. public function txtViewByAccount_Click($strFormId, $strControlId, $strParameter)
  165. {
  166. $this->intAccountId = $this->txtAccountNumberSearch->Text;
  167. $this->dtgOrders->Refresh();
  168. }
  169. public function lstStatus_Selected($strFormId, $strControlId, $strParameter)
  170. {
  171. $this->intOrderStatusId = $this->lstStatus->SelectedIndex;
  172. $this->dtgOrders->Refresh();
  173. }
  174. public function OrderDataBinder()
  175. {
  176. $objClauses = array();
  177. if ($objClause = $this->dtgOrders->OrderByClause)
  178. array_push($objClauses, $objClause);
  179. if ($objClause = $this->dtgOrders->LimitClause)
  180. array_push($objClauses, $objClause);
  181. if($this->intOrderStatusId && $this->intAccountId)
  182. {
  183. $this->dtgOrders->TotalItemCount = Order::QueryCount(QQ::AndCondition(
  184. QQ::Equal( QQN::Order()->AccountId, $this->intAccountId),
  185. QQ::Equal( QQN::Order()->StatusId, $this->intOrderStatusId)));
  186. $aryOrders = Order::QueryArray( QQ::AndCondition(
  187. QQ::Equal( QQN::Order()->AccountId, $this->intAccountId),
  188. QQ::Equal( QQN::Order()->StatusId, $this->intOrderStatusId)),
  189. $objClauses );
  190. }
  191. elseif($this->intOrderStatusId )
  192. {
  193. $this->dtgOrders->TotalItemCount = Order::QueryCount(QQ::Equal(QQN::Order()->StatusId, $this->intOrderStatusId));
  194. $aryOrders = Order::QueryArray(QQ::Equal( QQN::Order()->StatusId, $this->intOrderStatusId), $objClauses );
  195. }
  196. elseif($this->intAccountId )
  197. {
  198. $this->dtgOrders->TotalItemCount = Order::QueryCount(QQ::Equal(QQN::Order()->AccountId, $this->intAccountId));
  199. $aryOrders = Order::QueryArray(QQ::Equal( QQN::Order()->AccountId, $this->intAccountId), $objClauses );
  200. }
  201. else
  202. {
  203. $this->dtgOrders->TotalItemCount = Order::CountAll();
  204. $aryOrders = Order::LoadAll( $objClauses );
  205. }
  206. $this->dtgOrders->DataSource = $aryOrders;
  207. }
  208. public function btnCreateNew_Click($strFormId, $strControlId, $strParameter)
  209. {
  210. $objEditPanel = new OrderEditPanel($this, $this->strCloseEditPanelMethod, null);
  211. $strMethodName = $this->strSetEditPanelMethod;
  212. $this->objForm->$strMethodName($objEditPanel);
  213. }
  214. }
  215. ?>