Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- diff --git a/docs/dashboard/inventory/close_week.php b/docs/dashboard/inventory/close_week.php
- index 3da4dcf..d0ad5f9 100644
- --- a/docs/dashboard/inventory/close_week.php
- +++ b/docs/dashboard/inventory/close_week.php
- @@ -1,182 +1,36 @@
- <?php
- -require_once("$LIB_PATH/Vendors/VendorList.inc");
- -
- +//vl('in close_week.php');
- $session_obj = Session::get_instance();
- +$master_store_id = $session_obj->get_master_store_id();
- +$store_id = $session_obj->get_store_id();
- if (($_REQUEST['date'] && $_REQUEST['close_week']) || $_REQUEST['step1']) {
- - $vendorlist_obj = new VendorList($session_obj->get_master_store_id(), $session_obj->get_store_id());
- -
- - $invoice_list = array();
- - $db = DBConn::get_conn('app');
- - $db_dw = DBConn::get_conn('dw');
- -
- - $sql = 'select * from INVOICES
- - where COMPANY_ID = ' . $session_obj->get_store_id() . "
- - and DELETED = 'N'
- - and WEEK_END_DATE >= '". date("Y-m-d", strtotime("-6 days", strtotime($_REQUEST['date']))) ."'
- - and WEEK_END_DATE <= '{$_REQUEST['date']}'";
- -
- - if($stmt = $db->query($sql)) {
- - while ($row = $stmt->fetch()) {
- - $row['ITEM_TOTAL'] = ($row['SUBTOTAL'] + $row['DEPOSITS'] + $row['SHIPPING'] + $row['TAXES']) - ($row['CREDITS'] + $row['DISCOUNT']);
- - $invoice_list[] = $row;
- - }
- - $stmt->closeCursor();
- - }
- -
- - $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
- - where i.INVOICE_ID = ia.INVOICE_ID
- - and COMPANY_ID = ' . $session_obj->get_store_id() . "
- - and DELETED = 'N'
- - and WEEK_END_DATE >= '". date("Y-m-d", strtotime("-6 days", strtotime($_REQUEST['date']))) ."'
- - and WEEK_END_DATE <= '{$_REQUEST['date']}'
- - group by INVOICE_ID";
- -
- - if($stmt = $db->query($sql)) {
- - while ($row = $stmt->fetch()) {
- - $invoice_accounts[$row['INVOICE_ID']] = $row;
- - }
- - $stmt->closeCursor();
- - }
- -
- - $item_total_errors = array();
- - $gl_total_errors = array();
- - foreach ($invoice_list as $invoice) {
- - $fv_tot = round($invoice['TOTAL'], 2);
- - $fv_itot = round($invoice['ITEM_TOTAL'], 2);
- - if ($fv_tot != $fv_itot) {
- - $item_total_errors[] = $invoice['INVOICE_ID'];
- - }
- - elseif ($vendorlist_obj->vendor_list[$invoice['VENDOR_ID']]['SUPPLIER'] == 'N' and $fv_tot != round($invoice_accounts[$invoice['INVOICE_ID']]['TOTAL'], 2)) {
- - $gl_total_errors[] = $invoice['INVOICE_ID'];
- - }
- - }
- -
- -
- - // see if there are any outstanding TRANSFERS for the week
- - $start_date = date("Y-m-d", strtotime("-6 days", strtotime($_REQUEST['date'])));
- - $end_date = $_REQUEST['date'];
- -
- - $base_options = array('types' => array('TRANSFER'), 'pending' => 'Y');
- -
- - $pendingeventlist_obj = new InventoryEventList($session_obj->get_master_store_id(), $session_obj->get_store_id(), $start_date, $end_date, $base_options);
- -
- - if(!$pendingeventlist_obj->is_empty()) {
- - foreach($pendingeventlist_obj as $transferid => $transfer) {
- - $transfers_pending[] = $pendingeventlist_obj->get_initiator_transfer_id($transferid);
- - }
- - }
- -
- - // and now check for any unapproved vendor products
- - $itemslist_obj = new InventoryItemsList($session_obj->get_master_store_id(), $session_obj->get_store_id());
- - $itemslist_obj->load_unapproved_vendor_items(array('only_store_id' => $session_obj->get_store_id()));
- - $unapproved_count = $itemslist_obj->unapproved_vendor_item_count;
- -
- - $close_week_errors = false;
- -
- - if ( $unapproved_count > 0 ||
- - sizeof($item_total_errors) > 0 ||
- - sizeof($gl_total_errors) > 0 ||
- - sizeof($gl_total_errors) > 0
- - )
- - {
- - $close_week_errors = true;
- - }
- -
- - if (!$close_week_errors &&
- - $_REQUEST['date'] &&
- - $_REQUEST['close_week']
- - )
- - {
- - require_once("$LIB_PATH/Inventory/InventoryItemsList.inc");
- - require_once("$LIB_PATH/Counts/PhysicalCount.inc");
- -
- - $db = DBConn::get_conn('app');
- - $store_id = $session_obj->get_store_id();
- -
- - $debugging = false;
- - $yesterday = date('Y-m-d', strtotime($_REQUEST['date']));
- - $last_week = date('Y-m-d', strtotime('-6 days', strtotime($_REQUEST['date'])));
- -
- - // auto recalc all the counts
- - $count_stores = implode(',', $auto_close_stores);
- - $sql = "select COMPANY_ID, INVENTORY_COUNT_ID
- - from INVENTORY_COUNTS
- - where COMPANY_ID in ($store_id)
- - and DATE >= '$last_week'
- - and DATE <= '$yesterday'
- - and DELETED='N'";
- -
- - if ($debugging) {
- - vel($sql);
- - }
- -
- - if($stmt = $db->query($sql)) {
- - while ($row = $stmt->fetch()) {
- - $store_counts[] = $row['INVENTORY_COUNT_ID'];
- - }
- - $stmt->closeCursor();
- - }
- -
- - if (is_array($store_counts)) {
- - foreach ($store_counts as $count_id) {
- - $itemslist_obj = new InventoryItemsList($session_obj->get_master_store_id(), $store_id);
- - $count_obj = new PhysicalCount($session_obj->get_master_store_id(), $store_id, $itemslist_obj, 0, $count_id);
- - if(strtoupper($count_obj->count['PERIOD']) === 'WEEKLY') {
- - $count_obj->auto_recalculate_count();
- - if ($debugging) {
- - error_log("auto recalculate for $store_id count $count_id");
- - }
- - }
- - }
- - }
- -
- - $week_end_date = date('Y-m-d', strtotime($_REQUEST['date']));
- - // and mark the week closed
- - $sql = "replace into INVENTORY_CLOSED_WEEKS
- - (COMPANY_ID, WEEK_ENDING_DATE, CREATED, EMPLOYEE_ID)
- - values (" . $session_obj->get_store_id() . ", '$week_end_date', NOW(), " . $session_obj->get_employee_id() . ")";
- - $db->query($sql);
- -
- - // tell the inventory aggregation that it needs to redo this week
- - if ($db_dw && $session_obj->store_has_product('POS')) {
- -
- - $last_week = date("Y-m-d", strtotime("-6 days", strtotime($_REQUEST['date'])));
- - // we tell inventory aggr to run up to and including the end of the week
- - $run_until = date('Y-m-d', strtotime('+1 day', strtotime($week_end_date)));
- -
- - $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'";
- -error_log('manual close week ' . $sql);
- - $how_many = $db_dw->get_one($sql);
- - if (!$how_many) {
- - $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')";
- - $db_dw->exec($sql);
- - }
- - }
- -
- - $just_closed = date('n/j/Y', strtotime($week_end_date));
- - }
- -}
- -
- -
- + $end_date = $_REQUEST['date'];
- + $options = array();
- + $options['employee_id'] = $session_obj->get_employee_id();
- + $options['store_has_pos'] = $session_obj->store_has_product('POS');
- + $options['close_week'] = $_REQUEST['close_week'];
- + $closeweek_obj = new CloseWeek();
- + $closeweek_obj->resolve_week_invoices($master_store_id, $store_id, $end_date, $options);
- +
- +}
- $closed_week = $session_obj->get_inventory_closed_date(date("Y-m-d", $session_obj->get_store_attr('local_time')), true);
- -
- ######################################################################
- $template = new Template();
- $template->set('closed_week', $closed_week);
- -if ($close_week_errors) {
- - $template->set('invoice_list', $invoice_list);
- - $template->set('invoice_accounts', $invoice_accounts);
- - $template->set('item_total_errors', $item_total_errors);
- - $template->set('gl_total_errors', $gl_total_errors);
- - $template->set('transfers_pending', $transfers_pending);
- - $template->set('unapproved_count', $unapproved_count);
- - $template->set('close_week_errors', $close_week_errors);
- +if ($closeweek_obj->close_week_errors) {
- + $template->set('invoice_list', $closeweek_obj->invoice_list);
- + $template->set('invoice_accounts', $closeweek_obj->invoice_accounts);
- + $template->set('item_total_errors', $closeweek_obj->item_total_errors);
- + $template->set('gl_total_errors', $closeweek_obj->gl_total_errors);
- + $template->set('transfers_pending', $closeweek_obj->transfers_pending);
- + $template->set('unapproved_count', $closeweek_obj->unapproved_count);
- + $template->set('close_week_errors', $closeweek_obj->close_week_errors);
- } else {
- - $template->set('just_closed', $just_closed);
- - $template->set('invoice_list', $invoice_list);
- + $template->set('just_closed', $closeweek_obj->just_closed);
- + $template->set('invoice_list', $closeweek_obj->invoice_list);
- }
Add Comment
Please, Sign In to add comment