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.

274 lines
13 KiB

13 years ago
  1. <?php
  2. /**
  3. * This is a quick-and-dirty draft QPanel object to do Create, Edit, and Delete functionality
  4. * of the Order class. It uses the code-generated
  5. * OrderMetaControl class, which has meta-methods to help with
  6. * easily creating/defining controls to modify the fields of a Order columns.
  7. *
  8. * Any display customizations and presentation-tier logic can be implemented
  9. * here by overriding existing or implementing new methods, properties and variables.
  10. *
  11. * NOTE: This file is overwritten on any code regenerations. If you want to make
  12. * permanent changes, it is STRONGLY RECOMMENDED to move both order_edit.php AND
  13. * order_edit.tpl.php out of this Form Drafts directory.
  14. *
  15. * @package Quasi
  16. * @subpackage Drafts
  17. */
  18. class OrderEditPanel extends QPanel {
  19. // Local instance of the OrderMetaControl
  20. protected $mctOrder;
  21. protected $pnlListPanel;
  22. public $dtgOrderItems;
  23. public $pxyEditOrderItem;
  24. public $pxyViewProduct;
  25. public $objOrderItemsPaginator;
  26. public $lblOrderTotal;
  27. // Controls for Order's Data Fields
  28. public $lblId;
  29. public $lblAccount;
  30. public $lblCreationDate;
  31. public $lblLastModificationDate;
  32. public $lblCompletionDate;
  33. public $txtShippingCost;
  34. public $txtProductTotalCost;
  35. public $txtShippingCharged;
  36. public $txtHandlingCharged;
  37. public $txtTax;
  38. public $txtProductTotalCharged;
  39. public $txtShippingNamePrefix;
  40. public $txtShippingFirstName;
  41. public $txtShippingMiddleName;
  42. public $txtShippingLastName;
  43. public $txtShippingNameSuffix;
  44. public $txtShippingStreet1;
  45. public $txtShippingStreet2;
  46. public $txtShippingSuburb;
  47. public $txtShippingCounty;
  48. public $txtShippingCity;
  49. public $lstShippingZone;
  50. public $lstShippingCountry;
  51. public $txtShippingPostalCode;
  52. public $txtBillingNamePrefix;
  53. public $txtBillingFirstName;
  54. public $txtBillingMiddleName;
  55. public $txtBillingLastName;
  56. public $txtBillingNameSuffix;
  57. public $txtBillingStreet1;
  58. public $txtBillingStreet2;
  59. public $txtBillingSuburb;
  60. public $txtBillingCounty;
  61. public $txtBillingCity;
  62. public $lstBillingZone;
  63. public $lstBillingCountry;
  64. public $txtBillingPostalCode;
  65. public $txtNotes;
  66. public $lstShippingMethod;
  67. public $lstPaymentMethod;
  68. public $lstStatus;
  69. // Other ListBoxes (if applicable) via Unique ReverseReferences and ManyToMany References
  70. // Other Controls
  71. public $btnSave;
  72. public $btnDelete;
  73. public $btnCancel;
  74. // Callback
  75. protected $strClosePanelMethod;
  76. public function __construct($objParentObject, $strClosePanelMethod, $intId = null, $strControlId = null)
  77. {
  78. $this->pnlListPanel =& $objParentObject;
  79. try {
  80. parent::__construct($objParentObject, $strControlId);
  81. } catch (QCallerException $objExc) {
  82. $objExc->IncrementOffset();
  83. throw $objExc;
  84. }
  85. $this->strTemplate = 'OrderEditPanel.tpl.php';
  86. $this->strClosePanelMethod = $strClosePanelMethod;
  87. $this->mctOrder = OrderMetaControl::Create($this, $intId);
  88. $this->lblId = $this->mctOrder->lblId_Create();
  89. $this->lblId->Name = "Order Number:";
  90. $this->lblAccount = $this->mctOrder->lblAccountId_Create();
  91. $this->lblAccount->AddAction(new QClickEvent(), new QAjaxControlAction($this, 'lblAccount_Click'));
  92. $this->lblAccount->AddCssClass('button');
  93. $this->lblAccount->Name = 'Account No.: ' . $this->mctOrder->Order->AccountId;
  94. $this->lblCreationDate = $this->mctOrder->lblCreationDate_Create();
  95. $this->lblLastModificationDate = $this->mctOrder->lblLastModificationDate_Create();
  96. $this->lblCompletionDate = $this->mctOrder->lblCompletionDate_Create();
  97. $this->txtShippingCost = $this->mctOrder->txtShippingCost_Create();
  98. $this->txtProductTotalCost = $this->mctOrder->txtProductTotalCost_Create();
  99. $this->txtShippingCharged = $this->mctOrder->txtShippingCharged_Create();
  100. $this->txtHandlingCharged = $this->mctOrder->txtHandlingCharged_Create();
  101. $this->txtTax = $this->mctOrder->txtTax_Create();
  102. $this->txtProductTotalCharged = $this->mctOrder->txtProductTotalCharged_Create();
  103. $this->txtShippingNamePrefix = $this->mctOrder->txtShippingNamePrefix_Create();
  104. $this->txtShippingFirstName = $this->mctOrder->txtShippingFirstName_Create();
  105. $this->txtShippingMiddleName = $this->mctOrder->txtShippingMiddleName_Create();
  106. $this->txtShippingLastName = $this->mctOrder->txtShippingLastName_Create();
  107. $this->txtShippingNameSuffix = $this->mctOrder->txtShippingNameSuffix_Create();
  108. $this->txtShippingStreet1 = $this->mctOrder->txtShippingStreet1_Create();
  109. $this->txtShippingStreet2 = $this->mctOrder->txtShippingStreet2_Create();
  110. $this->txtShippingSuburb = $this->mctOrder->txtShippingSuburb_Create();
  111. $this->txtShippingCounty = $this->mctOrder->txtShippingCounty_Create();
  112. $this->txtShippingCity = $this->mctOrder->txtShippingCity_Create();
  113. $this->lstShippingZone = $this->mctOrder->lstShippingZone_Create();
  114. $this->lstShippingCountry = $this->mctOrder->lstShippingCountry_Create();
  115. $this->txtShippingPostalCode = $this->mctOrder->txtShippingPostalCode_Create();
  116. $this->txtBillingNamePrefix = $this->mctOrder->txtBillingNamePrefix_Create();
  117. $this->txtBillingFirstName = $this->mctOrder->txtBillingFirstName_Create();
  118. $this->txtBillingMiddleName = $this->mctOrder->txtBillingMiddleName_Create();
  119. $this->txtBillingLastName = $this->mctOrder->txtBillingLastName_Create();
  120. $this->txtBillingNameSuffix = $this->mctOrder->txtBillingNameSuffix_Create();
  121. $this->txtBillingStreet1 = $this->mctOrder->txtBillingStreet1_Create();
  122. $this->txtBillingStreet2 = $this->mctOrder->txtBillingStreet2_Create();
  123. $this->txtBillingSuburb = $this->mctOrder->txtBillingSuburb_Create();
  124. $this->txtBillingCounty = $this->mctOrder->txtBillingCounty_Create();
  125. $this->txtBillingCity = $this->mctOrder->txtBillingCity_Create();
  126. $this->lstBillingZone = $this->mctOrder->lstBillingZone_Create();
  127. $this->lstBillingCountry = $this->mctOrder->lstBillingCountry_Create();
  128. $this->txtBillingPostalCode = $this->mctOrder->txtBillingPostalCode_Create();
  129. $this->txtNotes = $this->mctOrder->txtNotes_Create();
  130. $this->lstShippingMethod = $this->mctOrder->lstShippingMethod_Create();
  131. $this->lstPaymentMethod = $this->mctOrder->lstPaymentMethod_Create();
  132. $this->lstStatus = $this->mctOrder->lstStatus_Create();
  133. $strOrderTotal = money_format("%n", $this->mctOrder->Order->ProductTotalCharged
  134. + $this->mctOrder->Order->ShippingCharged
  135. + $this->mctOrder->Order->HandlingCharged
  136. + $this->mctOrder->Order->Tax );
  137. $this->lblOrderTotal = new QLabel($this);
  138. $this->lblOrderTotal->Name = 'Order Total: ';
  139. $this->lblOrderTotal->Text = $strOrderTotal;
  140. // Create Buttons and Actions on this Form
  141. $this->btnSave = new QButton($this);
  142. $this->btnSave->Text = QApplication::Translate('Save');
  143. $this->btnSave->AddAction(new QClickEvent(), new QAjaxControlAction($this, 'btnSave_Click'));
  144. $this->btnSave->CausesValidation = $this;
  145. $this->btnCancel = new QButton($this);
  146. $this->btnCancel->Text = QApplication::Translate('Cancel');
  147. $this->btnCancel->AddAction(new QClickEvent(), new QAjaxControlAction($this, 'btnCancel_Click'));
  148. $this->btnDelete = new QButton($this);
  149. $this->btnDelete->Text = QApplication::Translate('Delete');
  150. $this->btnDelete->AddAction(new QClickEvent(), new QConfirmAction(QApplication::Translate('Are you SURE you want to DELETE this') . ' ' . QApplication::Translate('Order') . '?'));
  151. $this->btnDelete->AddAction(new QClickEvent(), new QAjaxControlAction($this, 'btnDelete_Click'));
  152. $this->btnDelete->Visible = $this->mctOrder->EditMode;
  153. $this->dtgOrderItems = new OrderItemDataGrid($this);
  154. $this->dtgOrderItems->CssClass = 'datagrid';
  155. $this->dtgOrderItems->SetDataBinder('OrderItemsDataBinder', $this);
  156. $this->dtgOrderItems->AlternateRowStyle->CssClass = 'alternate';
  157. $this->objOrderItemsPaginator = new QPaginator($this->dtgOrderItems);
  158. $this->dtgOrderItems->Paginator = $this->objOrderItemsPaginator;
  159. $this->dtgOrderItems->ItemsPerPage = 20;
  160. $this->pxyEditOrderItem = new QControlProxy($this);
  161. $this->pxyEditOrderItem->AddAction(new QClickEvent(), new QAjaxControlAction($this, 'pxyEditOrderItem_Click'));
  162. $this->pxyViewProduct = new QControlProxy($this);
  163. $this->pxyViewProduct->AddAction(new QClickEvent(), new QAjaxControlAction($this, 'pxyViewProduct_Click'));
  164. $this->dtgOrderItems->MetaAddEditProxyColumn($this->pxyEditOrderItem, 'Edit', 'Edit');
  165. $this->dtgOrderItems->MetaAddProxyColumn($this->pxyViewProduct, QQN::OrderItem()->Product);
  166. $this->dtgOrderItems->MetaAddColumn('Quantity');
  167. $strItemPriceParam = '<?= money_format("%n", $_ITEM->Product->RetailPrice ) ?>';
  168. $objItemPriceColumn = new QDataGridColumn('Item Price', $strItemPriceParam );
  169. $this->dtgOrderItems->AddColumn($objItemPriceColumn);
  170. $strItemTotalParam = '<?= money_format("%n", $_ITEM->Quantity '
  171. . ' * $_ITEM->Product->RetailPrice ) ?>';
  172. $objItemTotalColumn = new QDataGridColumn('Item Total', $strItemTotalParam );
  173. $this->dtgOrderItems->AddColumn($objItemTotalColumn);
  174. }
  175. public function lblAccount_Click($strFormId, $strControlId, $strParameter)
  176. {
  177. $objEditPanel = new AccountEditPanel($this->pnlListPanel, 'CloseEditPane', $this->mctOrder->Order->AccountId);
  178. $this->objForm->SetEditPane($objEditPanel);
  179. }
  180. public function pxyEditOrderItem_Click($strFormId, $strControlId, $strParameter)
  181. {
  182. $strParameterArray = explode(',', $strParameter);
  183. // $objEditPanel = new OrderItemEditPanel($this, $this->strCloseEditPanelMethod, $strParameterArray[0], $strParameterArray[1]);
  184. $objEditPanel = new OrderItemEditPanel($this->pnlListPanel, 'CloseEditPane', $strParameterArray[0], $strParameterArray[1]);
  185. $this->objForm->SetEditPane($objEditPanel);
  186. }
  187. public function pxyViewProduct_Click($strFormId, $strControlId, $strParameter)
  188. {
  189. $strParameterArray = explode(',', $strParameter);
  190. $objOrderItem = OrderItem::Load($strParameterArray[0], $strParameterArray[1]);
  191. // $objEditPanel = new OrderItemEditPanel($this, $this->strCloseEditPanelMethod, $strParameterArray[0], $strParameterArray[1]);
  192. $objEditPanel = new ProductEditPanel($this->pnlListPanel, 'CloseEditPane', $objOrderItem->ProductId);
  193. $this->objForm->SetEditPane($objEditPanel);
  194. }
  195. /**
  196. * This binds the OrderItems Datagrid data retrieval to this Order, the items listed in the Datagrid will be those
  197. * associated with this user in the database.
  198. *
  199. * If a paginator is set on this DataBinder, it will use it. If not, then no pagination will be used.
  200. * It will also perform any sorting requested in by clicking on the column titles in the Datagrid.
  201. */
  202. public function OrderItemsDataBinder()
  203. {
  204. if ($this->objOrderItemsPaginator)
  205. $this->dtgOrderItems->TotalItemCount = OrderItem::CountByOrderId($this->mctOrder->Order->Id) ;
  206. $objClauses = array();
  207. // If a column is selected to be sorted, and if that column has a OrderByClause set on it, then let's add
  208. // the OrderByClause to the $objClauses array - this is in the datagrid if the user clicks on column title
  209. if ($objClause = $this->dtgOrderItems->OrderByClause)
  210. array_push($objClauses, $objClause);
  211. // Add the LimitClause information, as well
  212. if ($objClause = $this->dtgOrderItems->LimitClause)
  213. array_push($objClauses, $objClause);
  214. // array_push($objClauses, QQ::OrderBy(QQN::OrderItem()->CreationDate, false) );
  215. $intOrderId = $this->mctOrder->Order->Id;
  216. $this->dtgOrderItems->DataSource = OrderItem::LoadArrayByOrderId(
  217. $intOrderId, $objClauses
  218. );
  219. }
  220. // Control AjaxAction Event Handlers
  221. public function btnSave_Click($strFormId, $strControlId, $strParameter) {
  222. // Delegate "Save" processing to the OrderMetaControl
  223. $this->mctOrder->SaveOrder();
  224. $this->CloseSelf(true);
  225. }
  226. public function btnDelete_Click($strFormId, $strControlId, $strParameter) {
  227. // Delegate "Delete" processing to the OrderMetaControl
  228. $this->mctOrder->DeleteOrder();
  229. $this->CloseSelf(true);
  230. }
  231. public function btnCancel_Click($strFormId, $strControlId, $strParameter) {
  232. $this->CloseSelf(false);
  233. }
  234. // Close Myself and Call ClosePanelMethod Callback
  235. protected function CloseSelf($blnChangesMade) {
  236. $strMethod = $this->strClosePanelMethod;
  237. $this->objForm->$strMethod($blnChangesMade);
  238. }
  239. }
  240. ?>