Skip to content

Commit

Permalink
Merge pull request #137 from cptechinc/ii-mvc
Browse files Browse the repository at this point in the history
Ii mvc #134
  • Loading branch information
Pauldro authored Apr 13, 2021
2 parents c59f707 + eba5382 commit bf87b91
Show file tree
Hide file tree
Showing 100 changed files with 3,322 additions and 2,399 deletions.
263 changes: 263 additions & 0 deletions site/controllers/classes/Mwm/binr/Binr.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,263 @@
<?php namespace Controllers\Wm;

use stdClass;
// Purl Library
use Purl\Url as Purl;
// Dplus Model
use WarehouseQuery, Warehouse;
// Dpluso Model
use BininfoQuery, Bininfo;
use WhsesessionQuery, Whsesession;
// ProcessWire Classes, Modules
use ProcessWire\Page, ProcessWire\Module, Processwire\SearchInventory, Processwire\WarehouseManagement;
// Dplus Classes
use Dplus\Wm\Binr as BinrCRUD;
// Mvc Controllers
use Mvc\Controllers\AbstractController;

class Binr extends AbstractController {
/** @var SearchInventory **/
private static $inventory;

/** @var WarehouseManagement **/
private static $whsem;

/** @var Warehouse **/
private static $warehouse;

/** @var Whsesession **/
private static $whsesession;

public static function index($data) {
$fields = ['scan|text', 'action|text', 'frombin|text', 'tobin|text'];
$data = self::sanitizeParametersShort($data, $fields);

if (empty($data->action) === false) {
return self::handleCRUD($data);
}

if (empty($data->scan) === false) {
return self::handleScan($data);
}

if (empty($data->serialnbr) === false || empty($data->lotnbr) === false || empty($data->itemID) === false) {
return self::handleItem($data);
}

return self::searchItemForm($data);
}

public static function handleCRUD($data) {
$data = self::sanitizeParametersShort($data, ['action|text', 'scan|text']);

switch ($data->action) {
case 'inventory-search':
$whsem = self::getWarehouseManagement();
$whsem->requestInventorySearch(strtoupper($data->scan));
$url = new Purl(self::pw('page')->url);
$url->query->set('scan', $data->scan);
self::pw('session')->redirect($url->getUrl(), $http301 = false);
break;
case 'bin-reassign';
$data = self::sanitizeParametersShort($data, ['itemID|text', 'frombin|text', 'tobin|text', 'serialnbr|text', 'lotnbr|text', 'qty|float']);
$binr = new BinrCRUD();
$binr->requestBinReassignment($data);
$params = explode('&', self::pw('input')->queryString());
$url = new Purl(self::pw('page')->url);
if (array_key_exists('frombin', $params)) {
$url->query->set('frombin', $params['frombin']);
}
if (array_key_exists('tobin', $params)) {
$url->query->set('tobin', $params['tobin']);
}
self::pw('session')->redirect($url->getUrl(), $http301 = false);
break;
}
}

public static function handleScan($data) {
$fields = ['scan|text', 'action|text', 'frombin|text', 'tobin|text', 'binID|text'];
$data = self::sanitizeParametersShort($data, $fields);

if (empty($data->action) === false) {
return self::handleCRUD($data);
}
$html = '';
$config = self::pw('config');
$modules = self::pw('modules');
$config->binr = $modules->get('ConfigsBinr');
/** @var SearchInventory **/
$inventory = self::getInventorySearch();
$resultscount = $inventory->query()->count();

if ($resultscount === 0) {
return $config->twig->render('warehouse/binr/inventory-results.twig', ['items' => []]);
}

if ($resultscount === 1) {
$item = $inventory->query()->findOne();
$url = self::pw('page')->binr_itemURL($item);
self::pw('session')->redirect($url, $http301 = false);
}

// Multiple Items - count the number Distinct Item IDs
$countItemids = $inventory->count_itemids_distinct($data->binID);

if ($countItemids === 1) {
return self::handleScanInventorySingleItemid($data);
}
$items = $inventory->get_items_distinct($data->binID);
return $config->twig->render('warehouse/binr/inventory-results.twig', ['resultscount' => $resultscount, 'items' => $items]);
}

private static function handleScanInventorySingleItemid($data) {
$fields = ['scan|text', 'action|text', 'frombin|text', 'tobin|text', 'binID|text'];
$data = self::sanitizeParametersShort($data, $fields);
$inventory = self::getInventorySearch();
$config = self::pw('config');

$q = $inventory->query();
if ($data->binID) {
$q->filterByBin($data->binID);
}
$item = $q->findOne();

if ($item->is_lotted() === false && $item->is_serialized() === false) {
$whsem = self::getWarehouseManagement();
$whsem->requestItemBins($item->itemid);
$url = new Purl(self::pw('page')->url);
$url->query->set('itemID', $item->itemid);
self::pw('session')->redirect($url->getUrl(), $http301 = false);
}

// If Item is Lotted / Serialized show results to choose which lot or serial to move
$countLotserial = $inventory->count_itemid_records($item->itemid, $data->binID);
$items = $inventory->get_items_distinct($data->binID);
$warehouse = self::getCurrentUserWarehouse();

if ($config->twigloader->exists("warehouse/binr/$config->company/inventory-results.twig")) {
return $config->twig->render("warehouse/binr/$config->company/inventory-results.twig", ['config' => $config->binr, 'resultscount' => $countLotserial, 'items' => $items, 'warehouse' => $warehouse, 'inventory' => $inventory]);
}
return $config->twig->render('warehouse/binr/inventory-results.twig', ['config' => $config->binr, 'resultscount' => $countLotserial, 'items' => $items, 'warehouse' => $warehouse, 'inventory' => $inventory]);
}

private static function handleItem($data) {
$fields = ['lotnbr|text', 'serialnbr|text', 'itemID|text', 'binID|text'];
$data = self::sanitizeParametersShort($data, $fields);
$page = self::pw('page');
$config = self::pw('config');
$warehouse = self::getCurrentUserWarehouse();
$inventory = self::getInventorySearch();
$whsesession = self::getWhseSession();

if ($data->lotnbr) {
$page->scan = $data->lotnbr;
$resultscount = $inventory->count_lotserial_records($data->lotnbr, $data->binID);
}
if ($data->serialnbr) {
$page->scan = $data->serialnbr;
$resultscount = $inventory->count_lotserial_records($data->serialnbr, $data->binID);
}
if ($data->itemID) {
$page->scan = $data->itemID;
$resultscount = $inventory->count_lotserial_records($data->itemID, $data->binID);
}

if ($resultscount > 1) {
$items = $inventory->get_items_distinct();
return $config->twig->render('warehouse/binr/inventory-results.twig', ['resultscount' => $resultscount, 'items' => $items, 'inventory' => $inventory]);
}

$html = '';

if (empty(self::pw('session')->get('binr')) === false) {
$html .= $config->twig->render('warehouse/binr/binr-result.twig', ['whsesession' => $whsesession, 'nexturl' => $page->url]);
self::pw('session')->remove('binr');
return $html;
}

// $resultscount == 1

// Prepare Binr Form
$item = $data->lotnbr || $data->serialnbr ? $inventory->get_lotserial($page->scan, $data->binID) : $inventory->get_invsearch_by_itemid($page->scan, $data->binID);
$currentbins = BininfoQuery::create()->filterByItem(session_id(), $item)->select_bin_qty()->find();
// 1. Binr form
$page->formurl = $page->parent('template=warehouse-menu')->child('template=redir')->url;
$html .= $config->twig->render('warehouse/binr/binr-form.twig', ['config' => $config->binr, 'whsesession' => $whsesession, 'item' => $item, 'inventory' => $inventory]);
// 2. Choose From Bin Modal
$html .= $config->twig->render('warehouse/binr/from-bins-modal.twig', ['config' => $config->binr, 'item' => $item, 'bins' => $currentbins]);
// 3. Choose To Bin Modals
$html .= $config->twig->render('warehouse/binr/to-bins-modal.twig', ['config' => $config->binr, 'currentbins' => $currentbins, 'warehouse' => $warehouse, 'item' => $item, 'inventory' => $inventory]);
// 4. Warehouse Config JS
$bins = $warehouse->get_bins();
$availablebins = BininfoQuery::create()->filterBySessionItemid(session_id(), $item->itemID)->find()->toArray('Bin');
$jsconfig = array('warehouse' => array('id' => $whsesession->whseid, 'binarrangement' => $warehouse->get_binarrangementdescription(), 'bins' => $bins));
$html .= $config->twig->render('util/js-variables.twig', ['variables' => array('warehouse' => $jsconfig, 'validfrombins' => $availablebins)]);
return $html;
}

private static function searchItemForm($data) {
$page = self::pw('page');
$config = self::pw('config');
$page->formurl = $page->url;
return $config->twig->render('warehouse/item-form.twig');
}

public static function getWarehouseManagement() {
if (empty(self::$whsem)) {
self::$whsem = self::pw('modules')->get('WarehouseManagement');
}
return self::$whsem;
}

public static function getInventorySearch() {
if (empty(self::$inventory)) {
self::$inventory = self::pw('modules')->get('SearchInventory');
}
return self::$inventory;
}

public static function getCurrentUserWarehouse() {
if (empty(self::$warehouse)) {
self::$warehouse = WarehouseQuery::create()->findOneById(self::pw('user')->whseid);
}
return self::$warehouse;
}

public static function getWhseSession() {
if (empty(self::$whsesession)) {
self::$whsesession = WhsesessionQuery::create()->findOneBySessionid(session_id());
}
return self::$whsesession;
}

public static function init() {
$wm = self::pw('modules')->get('WarehouseManagement');
$wm->addHook('Page::binr_itemURL', function($event) {
$p = $event->object;
$item = $event->arguments(0);
$url = new Purl($p->parent('template=warehouse-menu')->child('template=redir')->url);
$url->query->set('action','search-item-bins');
$url->query->set('itemID', $item->itemid);
$url->query->set($item->get_itemtypeproperty(), $item->get_itemidentifier());
$url->query->set('binID', $item->bin);
$url->query->set('page', $p->fullURL->getUrl());
$event->return = $url->getUrl();
});

$wm->addHookProperty('Page::scan', function($event) {
$p = $event->object;
$event->return = !empty($p->scan) ? $p->scan : false;
});

$wm->addHookProperty('Page::tobin', function($event) {
$p = $event->object;
$event->return = !empty($p->tobin) ? $p->tobin : '';
});

$wm->addHookProperty('Page::frombin', function($event) {
$p = $event->object;
$event->return = !empty($p->frombin) ? $p->frombin : '';
});
}
}
6 changes: 3 additions & 3 deletions site/controllers/classes/ajax/json/Map.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public static function getVxmByItemid($data) {
return $response;
}

public function validateVxmUpdateItmCost($data) {
public static function validateVxmUpdateItmCost($data) {
$fields = ['vendorID|text', 'vendoritemID|text', 'itemID|text', 'ordercode|text'];
$data = self::sanitizeParametersShort($data, $fields);
$response = ['allow' => false, 'confirm' => false];
Expand All @@ -149,8 +149,8 @@ public function validateVxmUpdateItmCost($data) {
$vxm = self::pw('modules')->get('XrefVxm');
$vxm->init_configs();
$xref = $vxm->xref($data->vendorID, $data->vendoritemID, $data->itemID);
if (array_key_exists($ordercode, ItemXrefVendor::OPTIONS_POORDERCODE)) {
$xref->setPo_ordercode($ordercode);
if (array_key_exists($data->ordercode, ItemXrefVendor::OPTIONS_POORDERCODE)) {
$xref->setPo_ordercode($data->ordercode);
}
$response['allow'] = $vxm->allow_itm_cost_update_xref($xref);
if ($response['allow']) {
Expand Down
Loading

0 comments on commit bf87b91

Please sign in to comment.