Files
crm.twinpol.com/modules/EcmInsideOrders.cp/makeProduction.php
2025-05-12 15:44:39 +00:00

140 lines
5.6 KiB
PHP
Executable File

<table cellspacing="0" cellpadding="0" border="0"><tr><td><img src="themes/Sugar/images/EcmProducts.gif" style="margin-top: 3px; margin-right: 3px;" alt="EcmProducts" width="16" border="0" height="16"></td><td><h2>Production: Make Production </h2></td></tr></table><br />
<?php
include_once("modules/EcmStockOperations/EcmStockOperation.php");
include_once("modules/EcmSales/productionHelper.php");
$op = new EcmStockOperation();
$rdoc=$GLOBALS['db']->fetchByAssoc($GLOBALS['db']->query("select * from ecminsideorders where id='".$_REQUEST['record']."'"));
$t.='<form action="index.php?module=EcmInsideOrders&action=saveProduction&record='.$_REQUEST['record'].'" method="post"><ul class="tablist" style="width:100%;">
<li>
<a class="current" href="#">RW</a>
</li>
</ul>';
$t.='<table style="border-top: 0px none; margin-bottom: 4px;width:100%" class="tabForm" border="0" cellpadding="0" cellspacing="0">
<tr>
<td class="dataLabel" width="10%" nowrap="nowrap">
Inventory</td>
<td class="dataField" width="30%" nowrap="nowrap">';
$rs=$GLOBALS['db']->fetchByAssoc($GLOBALS['db']->query("select name from ecmstocks where id='".$rdoc['rw_stock_id']."'"));$t.=$rs['name'];
$t.='</td>
</tr>
</table>';
$t.=$tbs;
$t.=$trs;
$t.=$tds1;
$t.="Index";
$t.=$tde;
$t.=$tds1;
$t.="Name";
$t.=$tde;
$t.=$tds1;
$t.="Inventory";
$t.=$tde;
$t.=$tds1;
$t.="Quantity";
$t.=$tde;
$t.=$tre;
$w=$GLOBALS['db']->query("select * from ecmproducts_ecminsideorders where product_component=1 and deleted='0' and ecminsideorder_id='".$_REQUEST['record']."'");
$used = array();
while($r=$GLOBALS['db']->fetchByAssoc($w)){
$cat = $GLOBALS['db']->fetchByAssoc($GLOBALS['db']->query("SELECT product_category_id as cat FROM ecmproducts WHERE id='".$r['ecmproduct_id']."'"));
$stop=0;
//uwzględniamy już użyte
$stock=($op->getStock($r['ecmproduct_id'],$rdoc['rw_stock_id'])-$used[$r['ecmproduct_id']]);
if (!isset($used[$r['ecmproduct_id']])) $used[$r['ecmproduct_id']] = 0;
if ($cat['cat']!='d7f876b0-1a3d-43a1-7c9b-511ba40df3d1')
$used[$r['ecmproduct_id']]+=$r['product_prod_quantity'];
$t.=$trs.$tds.$r['product_code'].$tde.$tds.$r['product_name'].$tde.$tds.$stock.$tde.$tds.$r['product_prod_quantity'].$tde.$tre;
if($stock<$r['product_prod_quantity'])$stop=1;
if($stop && $cat['cat']!='d7f876b0-1a3d-43a1-7c9b-511ba40df3d1'){
$t.=$trs.$tds."&nbsp;".$tde.$tds."<span style=\"color:red\">no products in stock</span>".$tde.$tds."&nbsp;".$tde.$tds."&nbsp;".$tde.$tre;
$stop_arr[$r['product_guid']]=$r['product_guid'];
}
else{
$rw_prod[]=array("id"=>$r['ecmproduct_id'],"quantity"=>$r['product_prod_quantity'],"guid"=>$r['product_guid'],'price'=>$r['product_price']);
}
}
$t.=$tbe;
$t.='<br><ul class="tablist" style="width:100%;">
<li>
<a class="current" href="#">PW</a>
</li>
</ul>';
$t.='<table style="border-top: 0px none; margin-bottom: 4px;width:100%" class="tabForm" border="0" cellpadding="0" cellspacing="0">
<tr>
<td class="dataLabel" width="10%" nowrap="nowrap">
Inventory</td>
<td class="dataField" width="30%" nowrap="nowrap">';
$rs=$GLOBALS['db']->fetchByAssoc($GLOBALS['db']->query("select name from ecmstocks where id='".$rdoc['pw_stock_id']."'"));$t.=$rs['name'];
$t.='</td>
</tr>
</table>';
$t.=$tbs;
$t.=$trs;
$t.=$tds1;
$t.="Index";
$t.=$tde;
$t.=$tds1;
$t.="Name";
$t.=$tde;
$t.=$tds1;
$t.="Inventory";
$t.=$tde;
$t.=$tds1;
$t.="Quantity";
$t.=$tde;
$t.=$tds1;
$t.="Price";
$t.=$tde;
$t.=$tre;
$w=$GLOBALS['db']->query("select * from ecmproducts_ecminsideorders where product_component!=1 and deleted='0' and ecminsideorder_id='".$_REQUEST['record']."'");
while($r=$GLOBALS['db']->fetchByAssoc($w)){
if(in_array($r['product_guid'],$stop_arr))$stop="<br><span style=\"color:red\">no products in stock</span>";
else {
$stop="";
$pw_prod[]=array("id"=>$r['ecmproduct_id'],"quantity"=>$r['product_prod_quantity'],"price"=>$r['product_price'],"guid"=>$r['product_guid']);
}
$t.=$trs.$tds.$r['product_code'].$tde.$tds.$r['product_name'].$stop.$tde.$tds.$op->getStock($r['ecmproduct_id'],$rdoc['pw_stock_id']).$tde.$tds.$r['product_prod_quantity'].$tde.$tds.$r['product_price'].$tde.$tre;
}
$t.=$tbe;
//generate inputs
//rw
$t.='<input type="hidden" name="rw_stock" value="'.$rdoc['rw_stock_id'].'">';
if(count($rw_prod)>0){
foreach($rw_prod as $rp){
$t.='<input type="hidden" name="rw_id[]" value="'.$rp['id'].'">';
$t.='<input type="hidden" name="rw_quantity[]" value="'.$rp['quantity'].'">';
$t.='<input type="hidden" name="rw_price[]" value="'.$rp['price'].'">';
$t.='<input type="hidden" name="rw_guid[]" value="'.$rp['guid'].'">';
}
}
//pw
$t.='<input type="hidden" name="pw_stock" value="'.$rdoc['pw_stock_id'].'">';
if(count($pw_prod)>0){
foreach($pw_prod as $pp){
$t.='<input type="hidden" name="pw_id[]" value="'.$pp['id'].'">';
$t.='<input type="hidden" name="pw_quantity[]" value="'.$pp['quantity'].'">';
$t.='<input type="hidden" name="pw_price[]" value="'.$pp['price'].'">';
$t.='<input type="hidden" name="pw_guid[]" value="'.$pp['guid'].'">';
}
}
function check0stocks($d){
if(count($d)>0){
foreach($d as $dd){
if ($dd['category_id']='d7f876b0-1a3d-43a1-7c9b-511ba40df3d1') continue;
if($dd['quantity']==0 || $dd['quantity']=="")return false;
}
}
return true;
}
if(check0stocks($rw_prod) && check0stocks($pw_prod) && count($stop_arr)==0)$t.='<br><input type="submit" class="button" name="save_documents" value="Confirm" />';
else $t.="<br>Check stocks or please fill production quantities in Inside Order";
$t.='</form>';
echo $t;
?>