A QCodo powered CMS
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.

226 lines
9.6 KiB

  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 Quinta
  16. * @subpackage AdminUI
  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 $lblLastModification;
  32. public $calCompletionDate;
  33. public $txtProductTotalCost;
  34. public $txtShippingCost;
  35. public $txtShippingCharged;
  36. public $txtHandlingCost;
  37. public $txtHandlingCharged;
  38. public $txtTax;
  39. public $txtProductTotalCharged;
  40. public $txtNotes;
  41. public $lstShippingMethod;
  42. public $lstPaymentMethod;
  43. public $lstStatus;
  44. public $lstType;
  45. // Other ListBoxes (if applicable) via Unique ReverseReferences and ManyToMany References
  46. // Other Controls
  47. public $btnSave;
  48. public $btnDelete;
  49. public $btnCancel;
  50. // Callback
  51. protected $strClosePanelMethod;
  52. public function __construct($objParentObject, $strClosePanelMethod, $intId = null, $strControlId = null)
  53. {
  54. $this->pnlListPanel =& $objParentObject;
  55. try {
  56. parent::__construct($objParentObject, $strControlId);
  57. } catch (QCallerException $objExc) {
  58. $objExc->IncrementOffset();
  59. throw $objExc;
  60. }
  61. $this->strTemplate = 'OrderEditPanel.tpl.php';
  62. $this->strClosePanelMethod = $strClosePanelMethod;
  63. $this->mctOrder = OrderMetaControl::Create($this, $intId);
  64. $this->lblId = $this->mctOrder->lblId_Create();
  65. $this->lblId->Name = "Order Number:";
  66. $this->lblAccount = $this->mctOrder->lblAccountId_Create();
  67. $this->lblAccount->AddAction(new QClickEvent(), new QAjaxControlAction($this, 'lblAccount_Click'));
  68. $this->lblAccount->AddCssClass('button');
  69. $this->lblAccount->Name = 'Account No.: ' . $this->mctOrder->Order->AccountId;
  70. $this->lblCreationDate = $this->mctOrder->lblCreationDate_Create();
  71. $this->lblLastModification = $this->mctOrder->lblLastModification_Create();
  72. $this->calCompletionDate = $this->mctOrder->calCompletionDate_Create();
  73. $this->txtProductTotalCost = $this->mctOrder->txtProductTotalCost_Create();
  74. $this->txtShippingCost = $this->mctOrder->txtShippingCost_Create();
  75. $this->txtShippingCharged = $this->mctOrder->txtShippingCharged_Create();
  76. $this->txtHandlingCost = $this->mctOrder->txtHandlingCost_Create();
  77. $this->txtHandlingCharged = $this->mctOrder->txtHandlingCharged_Create();
  78. $this->txtTax = $this->mctOrder->txtTax_Create();
  79. $this->txtProductTotalCharged = $this->mctOrder->txtProductTotalCharged_Create();
  80. $this->txtNotes = $this->mctOrder->txtNotes_Create();
  81. $this->lstShippingMethod = $this->mctOrder->lstShippingMethod_Create();
  82. $this->lstPaymentMethod = $this->mctOrder->lstPaymentMethod_Create();
  83. $this->lstStatus = $this->mctOrder->lstStatus_Create();
  84. $this->lstType = $this->mctOrder->lstType_Create();
  85. $strOrderTotal = money_format("%n", $this->mctOrder->Order->ProductTotalCharged
  86. + $this->mctOrder->Order->ShippingCharged
  87. + $this->mctOrder->Order->HandlingCharged
  88. + $this->mctOrder->Order->Tax );
  89. $this->lblOrderTotal = new QLabel($this);
  90. $this->lblOrderTotal->Name = 'Order Total: ';
  91. $this->lblOrderTotal->Text = $strOrderTotal;
  92. // Create Buttons and Actions on this Form
  93. $this->btnSave = new QButton($this);
  94. $this->btnSave->Text = QApplication::Translate('Save');
  95. $this->btnSave->AddAction(new QClickEvent(), new QAjaxControlAction($this, 'btnSave_Click'));
  96. $this->btnSave->CausesValidation = $this;
  97. $this->btnCancel = new QButton($this);
  98. $this->btnCancel->Text = QApplication::Translate('Cancel');
  99. $this->btnCancel->AddAction(new QClickEvent(), new QAjaxControlAction($this, 'btnCancel_Click'));
  100. $this->btnDelete = new QButton($this);
  101. $this->btnDelete->Text = QApplication::Translate('Delete');
  102. $this->btnDelete->AddAction(new QClickEvent(), new QConfirmAction(QApplication::Translate('Are you SURE you want to DELETE this') . ' ' . QApplication::Translate('Order') . '?'));
  103. $this->btnDelete->AddAction(new QClickEvent(), new QAjaxControlAction($this, 'btnDelete_Click'));
  104. $this->btnDelete->Visible = $this->mctOrder->EditMode;
  105. $this->dtgOrderItems = new OrderItemDataGrid($this);
  106. $this->dtgOrderItems->CssClass = 'datagrid';
  107. $this->dtgOrderItems->SetDataBinder('OrderItemsDataBinder', $this);
  108. $this->dtgOrderItems->AlternateRowStyle->CssClass = 'alternate';
  109. $this->objOrderItemsPaginator = new QPaginator($this->dtgOrderItems);
  110. $this->dtgOrderItems->Paginator = $this->objOrderItemsPaginator;
  111. $this->dtgOrderItems->ItemsPerPage = 20;
  112. $this->pxyEditOrderItem = new QControlProxy($this);
  113. $this->pxyEditOrderItem->AddAction(new QClickEvent(), new QAjaxControlAction($this, 'pxyEditOrderItem_Click'));
  114. $this->pxyViewProduct = new QControlProxy($this);
  115. $this->pxyViewProduct->AddAction(new QClickEvent(), new QAjaxControlAction($this, 'pxyViewProduct_Click'));
  116. $this->dtgOrderItems->MetaAddEditProxyColumn($this->pxyEditOrderItem, 'Edit', 'Edit');
  117. $this->dtgOrderItems->MetaAddProxyColumn($this->pxyViewProduct, QQN::OrderItem()->Product);
  118. $this->dtgOrderItems->MetaAddColumn('Quantity');
  119. $strItemPriceParam = '<?= money_format("%n", $_ITEM->Product->RetailPrice ) ?>';
  120. $objItemPriceColumn = new QDataGridColumn('Item Price', $strItemPriceParam );
  121. $this->dtgOrderItems->AddColumn($objItemPriceColumn);
  122. $strItemTotalParam = '<?= money_format("%n", $_ITEM->Quantity '
  123. . ' * $_ITEM->Product->RetailPrice ) ?>';
  124. $objItemTotalColumn = new QDataGridColumn('Item Total', $strItemTotalParam );
  125. $this->dtgOrderItems->AddColumn($objItemTotalColumn);
  126. }
  127. public function lblAccount_Click($strFormId, $strControlId, $strParameter)
  128. {
  129. $objEditPanel = new AccountEditPanel($this->pnlListPanel, 'CloseEditPane', $this->mctOrder->Order->AccountId);
  130. $this->objForm->SetEditPane($objEditPanel);
  131. }
  132. public function pxyEditOrderItem_Click($strFormId, $strControlId, $strParameter)
  133. {
  134. $strParameterArray = explode(',', $strParameter);
  135. // $objEditPanel = new OrderItemEditPanel($this, $this->strCloseEditPanelMethod, $strParameterArray[0], $strParameterArray[1]);
  136. $objEditPanel = new OrderItemEditPanel($this->pnlListPanel, 'CloseEditPane', $strParameterArray[0], $strParameterArray[1]);
  137. $this->objForm->SetEditPane($objEditPanel);
  138. }
  139. public function pxyViewProduct_Click($strFormId, $strControlId, $strParameter)
  140. {
  141. $strParameterArray = explode(',', $strParameter);
  142. $objOrderItem = OrderItem::Load($strParameterArray[0], $strParameterArray[1]);
  143. // $objEditPanel = new OrderItemEditPanel($this, $this->strCloseEditPanelMethod, $strParameterArray[0], $strParameterArray[1]);
  144. $objEditPanel = new ProductEditPanel($this->pnlListPanel, 'CloseEditPane', $objOrderItem->ProductId);
  145. $this->objForm->SetEditPane($objEditPanel);
  146. }
  147. /**
  148. * This binds the OrderItems Datagrid data retrieval to this Order, the items listed in the Datagrid will be those
  149. * associated with this user in the database.
  150. *
  151. * If a paginator is set on this DataBinder, it will use it. If not, then no pagination will be used.
  152. * It will also perform any sorting requested in by clicking on the column titles in the Datagrid.
  153. */
  154. public function OrderItemsDataBinder()
  155. {
  156. if ($this->objOrderItemsPaginator)
  157. $this->dtgOrderItems->TotalItemCount = OrderItem::CountByOrderId($this->mctOrder->Order->Id) ;
  158. $objClauses = array();
  159. // If a column is selected to be sorted, and if that column has a OrderByClause set on it, then let's add
  160. // the OrderByClause to the $objClauses array - this is in the datagrid if the user clicks on column title
  161. if ($objClause = $this->dtgOrderItems->OrderByClause)
  162. array_push($objClauses, $objClause);
  163. // Add the LimitClause information, as well
  164. if ($objClause = $this->dtgOrderItems->LimitClause)
  165. array_push($objClauses, $objClause);
  166. // array_push($objClauses, QQ::OrderBy(QQN::OrderItem()->CreationDate, false) );
  167. $intOrderId = $this->mctOrder->Order->Id;
  168. $this->dtgOrderItems->DataSource = OrderItem::LoadArrayByOrderId(
  169. $intOrderId, $objClauses
  170. );
  171. }
  172. // Control AjaxAction Event Handlers
  173. public function btnSave_Click($strFormId, $strControlId, $strParameter) {
  174. // Delegate "Save" processing to the OrderMetaControl
  175. $this->mctOrder->SaveOrder();
  176. $this->CloseSelf(true);
  177. }
  178. public function btnDelete_Click($strFormId, $strControlId, $strParameter) {
  179. // Delegate "Delete" processing to the OrderMetaControl
  180. $this->mctOrder->DeleteOrder();
  181. $this->CloseSelf(true);
  182. }
  183. public function btnCancel_Click($strFormId, $strControlId, $strParameter) {
  184. $this->CloseSelf(false);
  185. }
  186. // Close Myself and Call ClosePanelMethod Callback
  187. protected function CloseSelf($blnChangesMade) {
  188. $strMethod = $this->strClosePanelMethod;
  189. $this->objForm->$strMethod($blnChangesMade);
  190. }
  191. }
  192. ?>