Guest User

Untitled

a guest
Jul 19th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.24 KB | None | 0 0
  1. diff --git a/docs/dashboard/inventory/close_week.php b/docs/dashboard/inventory/close_week.php
  2. index 3da4dcf..d0ad5f9 100644
  3. --- a/docs/dashboard/inventory/close_week.php
  4. +++ b/docs/dashboard/inventory/close_week.php
  5. @@ -1,182 +1,36 @@
  6. <?php
  7. -require_once("$LIB_PATH/Vendors/VendorList.inc");
  8. -
  9. +//vl('in close_week.php');
  10. $session_obj = Session::get_instance();
  11.  
  12. +$master_store_id = $session_obj->get_master_store_id();
  13. +$store_id = $session_obj->get_store_id();
  14. if (($_REQUEST['date'] && $_REQUEST['close_week']) || $_REQUEST['step1']) {
  15. - $vendorlist_obj = new VendorList($session_obj->get_master_store_id(), $session_obj->get_store_id());
  16. -
  17. - $invoice_list = array();
  18. - $db = DBConn::get_conn('app');
  19. - $db_dw = DBConn::get_conn('dw');
  20. -
  21. - $sql = 'select * from INVOICES
  22. - where COMPANY_ID = ' . $session_obj->get_store_id() . "
  23. - and DELETED = 'N'
  24. - and WEEK_END_DATE >= '". date("Y-m-d", strtotime("-6 days", strtotime($_REQUEST['date']))) ."'
  25. - and WEEK_END_DATE <= '{$_REQUEST['date']}'";
  26. -
  27. - if($stmt = $db->query($sql)) {
  28. - while ($row = $stmt->fetch()) {
  29. - $row['ITEM_TOTAL'] = ($row['SUBTOTAL'] + $row['DEPOSITS'] + $row['SHIPPING'] + $row['TAXES']) - ($row['CREDITS'] + $row['DISCOUNT']);
  30. - $invoice_list[] = $row;
  31. - }
  32. - $stmt->closeCursor();
  33. - }
  34. -
  35. - $sql = 'select i.INVOICE_ID, sum(ia.SUBTOTAL) as SUBTOTAL, sum(ia.DEPOSITS) as DEPOSITS, sum(ia.SHIPPING) as SHIPPING, sum(ia.TAXES) as TAXES, sum(ia.CREDITS) as CREDITS, sum(ia.DISCOUNT) as DISCOUNT, sum(ia.SUBTOTAL + ia.DEPOSITS + ia.SHIPPING + ia.TAXES - (ia.CREDITS + ia.DISCOUNT)) as TOTAL from INVOICE_GL_ACCOUNTS ia, INVOICES i
  36. - where i.INVOICE_ID = ia.INVOICE_ID
  37. - and COMPANY_ID = ' . $session_obj->get_store_id() . "
  38. - and DELETED = 'N'
  39. - and WEEK_END_DATE >= '". date("Y-m-d", strtotime("-6 days", strtotime($_REQUEST['date']))) ."'
  40. - and WEEK_END_DATE <= '{$_REQUEST['date']}'
  41. - group by INVOICE_ID";
  42. -
  43. - if($stmt = $db->query($sql)) {
  44. - while ($row = $stmt->fetch()) {
  45. - $invoice_accounts[$row['INVOICE_ID']] = $row;
  46. - }
  47. - $stmt->closeCursor();
  48. - }
  49. -
  50. - $item_total_errors = array();
  51. - $gl_total_errors = array();
  52. - foreach ($invoice_list as $invoice) {
  53. - $fv_tot = round($invoice['TOTAL'], 2);
  54. - $fv_itot = round($invoice['ITEM_TOTAL'], 2);
  55. - if ($fv_tot != $fv_itot) {
  56. - $item_total_errors[] = $invoice['INVOICE_ID'];
  57. - }
  58. - elseif ($vendorlist_obj->vendor_list[$invoice['VENDOR_ID']]['SUPPLIER'] == 'N' and $fv_tot != round($invoice_accounts[$invoice['INVOICE_ID']]['TOTAL'], 2)) {
  59. - $gl_total_errors[] = $invoice['INVOICE_ID'];
  60. - }
  61. - }
  62. -
  63. -
  64. - // see if there are any outstanding TRANSFERS for the week
  65. - $start_date = date("Y-m-d", strtotime("-6 days", strtotime($_REQUEST['date'])));
  66. - $end_date = $_REQUEST['date'];
  67. -
  68. - $base_options = array('types' => array('TRANSFER'), 'pending' => 'Y');
  69. -
  70. - $pendingeventlist_obj = new InventoryEventList($session_obj->get_master_store_id(), $session_obj->get_store_id(), $start_date, $end_date, $base_options);
  71. -
  72. - if(!$pendingeventlist_obj->is_empty()) {
  73. - foreach($pendingeventlist_obj as $transferid => $transfer) {
  74. - $transfers_pending[] = $pendingeventlist_obj->get_initiator_transfer_id($transferid);
  75. - }
  76. - }
  77. -
  78. - // and now check for any unapproved vendor products
  79. - $itemslist_obj = new InventoryItemsList($session_obj->get_master_store_id(), $session_obj->get_store_id());
  80. - $itemslist_obj->load_unapproved_vendor_items(array('only_store_id' => $session_obj->get_store_id()));
  81. - $unapproved_count = $itemslist_obj->unapproved_vendor_item_count;
  82. -
  83. - $close_week_errors = false;
  84. -
  85. - if ( $unapproved_count > 0 ||
  86. - sizeof($item_total_errors) > 0 ||
  87. - sizeof($gl_total_errors) > 0 ||
  88. - sizeof($gl_total_errors) > 0
  89. - )
  90. - {
  91. - $close_week_errors = true;
  92. - }
  93. -
  94. - if (!$close_week_errors &&
  95. - $_REQUEST['date'] &&
  96. - $_REQUEST['close_week']
  97. - )
  98. - {
  99. - require_once("$LIB_PATH/Inventory/InventoryItemsList.inc");
  100. - require_once("$LIB_PATH/Counts/PhysicalCount.inc");
  101. -
  102. - $db = DBConn::get_conn('app');
  103. - $store_id = $session_obj->get_store_id();
  104. -
  105. - $debugging = false;
  106. - $yesterday = date('Y-m-d', strtotime($_REQUEST['date']));
  107. - $last_week = date('Y-m-d', strtotime('-6 days', strtotime($_REQUEST['date'])));
  108. -
  109. - // auto recalc all the counts
  110. - $count_stores = implode(',', $auto_close_stores);
  111. - $sql = "select COMPANY_ID, INVENTORY_COUNT_ID
  112. - from INVENTORY_COUNTS
  113. - where COMPANY_ID in ($store_id)
  114. - and DATE >= '$last_week'
  115. - and DATE <= '$yesterday'
  116. - and DELETED='N'";
  117. -
  118. - if ($debugging) {
  119. - vel($sql);
  120. - }
  121. -
  122. - if($stmt = $db->query($sql)) {
  123. - while ($row = $stmt->fetch()) {
  124. - $store_counts[] = $row['INVENTORY_COUNT_ID'];
  125. - }
  126. - $stmt->closeCursor();
  127. - }
  128. -
  129. - if (is_array($store_counts)) {
  130. - foreach ($store_counts as $count_id) {
  131. - $itemslist_obj = new InventoryItemsList($session_obj->get_master_store_id(), $store_id);
  132. - $count_obj = new PhysicalCount($session_obj->get_master_store_id(), $store_id, $itemslist_obj, 0, $count_id);
  133. - if(strtoupper($count_obj->count['PERIOD']) === 'WEEKLY') {
  134. - $count_obj->auto_recalculate_count();
  135. - if ($debugging) {
  136. - error_log("auto recalculate for $store_id count $count_id");
  137. - }
  138. - }
  139. - }
  140. - }
  141. -
  142. - $week_end_date = date('Y-m-d', strtotime($_REQUEST['date']));
  143. - // and mark the week closed
  144. - $sql = "replace into INVENTORY_CLOSED_WEEKS
  145. - (COMPANY_ID, WEEK_ENDING_DATE, CREATED, EMPLOYEE_ID)
  146. - values (" . $session_obj->get_store_id() . ", '$week_end_date', NOW(), " . $session_obj->get_employee_id() . ")";
  147. - $db->query($sql);
  148. -
  149. - // tell the inventory aggregation that it needs to redo this week
  150. - if ($db_dw && $session_obj->store_has_product('POS')) {
  151. -
  152. - $last_week = date("Y-m-d", strtotime("-6 days", strtotime($_REQUEST['date'])));
  153. - // we tell inventory aggr to run up to and including the end of the week
  154. - $run_until = date('Y-m-d', strtotime('+1 day', strtotime($week_end_date)));
  155. -
  156. - $sql = "select count(*) from pos_data_loads where company_id = $store_id and start_time = '$last_week' and end_time = '$today' and data_type = 'inventory' and count > 0 and aggregated = 'N' and status = 'SUCCESS' and type = 'BULK'";
  157. -error_log('manual close week ' . $sql);
  158. - $how_many = $db_dw->get_one($sql);
  159. - if (!$how_many) {
  160. - $sql = "insert into pos_data_loads (company_id, load_time, start_time, end_time, data_type, count, aggregated, status, type) values ($store_id, NOW(), '$last_week', '$run_until', 'inventory', 1, 'N', 'SUCCESS', 'BULK')";
  161. - $db_dw->exec($sql);
  162. - }
  163. - }
  164. -
  165. - $just_closed = date('n/j/Y', strtotime($week_end_date));
  166. - }
  167. -}
  168. -
  169. -
  170. + $end_date = $_REQUEST['date'];
  171. + $options = array();
  172. + $options['employee_id'] = $session_obj->get_employee_id();
  173. + $options['store_has_pos'] = $session_obj->store_has_product('POS');
  174. + $options['close_week'] = $_REQUEST['close_week'];
  175. + $closeweek_obj = new CloseWeek();
  176. + $closeweek_obj->resolve_week_invoices($master_store_id, $store_id, $end_date, $options);
  177. +
  178. +}
  179. $closed_week = $session_obj->get_inventory_closed_date(date("Y-m-d", $session_obj->get_store_attr('local_time')), true);
  180. -
  181. ######################################################################
  182.  
  183. $template = new Template();
  184. $template->set('closed_week', $closed_week);
  185.  
  186. -if ($close_week_errors) {
  187. - $template->set('invoice_list', $invoice_list);
  188. - $template->set('invoice_accounts', $invoice_accounts);
  189. - $template->set('item_total_errors', $item_total_errors);
  190. - $template->set('gl_total_errors', $gl_total_errors);
  191. - $template->set('transfers_pending', $transfers_pending);
  192. - $template->set('unapproved_count', $unapproved_count);
  193. - $template->set('close_week_errors', $close_week_errors);
  194. +if ($closeweek_obj->close_week_errors) {
  195. + $template->set('invoice_list', $closeweek_obj->invoice_list);
  196. + $template->set('invoice_accounts', $closeweek_obj->invoice_accounts);
  197. + $template->set('item_total_errors', $closeweek_obj->item_total_errors);
  198. + $template->set('gl_total_errors', $closeweek_obj->gl_total_errors);
  199. + $template->set('transfers_pending', $closeweek_obj->transfers_pending);
  200. + $template->set('unapproved_count', $closeweek_obj->unapproved_count);
  201. + $template->set('close_week_errors', $closeweek_obj->close_week_errors);
  202. } else {
  203. - $template->set('just_closed', $just_closed);
  204. - $template->set('invoice_list', $invoice_list);
  205. + $template->set('just_closed', $closeweek_obj->just_closed);
  206. + $template->set('invoice_list', $closeweek_obj->invoice_list);
  207.  
  208. }
Add Comment
Please, Sign In to add comment