fix regulate / apply new PMP / add or remove line
This commit is contained in:
parent
9f6f874655
commit
1596760d21
@ -35,6 +35,7 @@ class CoreObject extends CommonObject {
|
||||
|
||||
public $date_0 = '1001-01-01 00:00:00'; //TODO there is a solution for this ?
|
||||
|
||||
public $error = '';
|
||||
/*
|
||||
* @var Array $_fields Fields to synchronize with Database
|
||||
*/
|
||||
@ -244,6 +245,8 @@ class CoreObject extends CommonObject {
|
||||
return $this->id;
|
||||
}
|
||||
else {
|
||||
$this->error = $this->db->lasterror();
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -335,7 +338,7 @@ class CoreObject extends CommonObject {
|
||||
if(empty($this->id )) return $this->create($user); // To test, with that, no need to test on high level object, the core decide it, update just needed
|
||||
|
||||
if(isset($this->to_delete) && $this->to_delete==true) {
|
||||
$this->delete();
|
||||
$this->delete($user);
|
||||
}
|
||||
else {
|
||||
|
||||
@ -345,13 +348,21 @@ class CoreObject extends CommonObject {
|
||||
$query['rowid']=$this->id;
|
||||
if(empty($this->no_update_tms))$query['tms'] = date('Y-m-d H:i:s');
|
||||
|
||||
$this->db->update($this->table_element,$query,array('rowid'));
|
||||
$res = $this->db->update($this->table_element,$query,array('rowid'));
|
||||
|
||||
$this->id = $this->db->last_insert_id($this->table_element);
|
||||
if($res) {
|
||||
|
||||
$result = $this->call_trigger(strtoupper($this->element). '_UPDATE', $user);
|
||||
|
||||
$result = $this->call_trigger(strtoupper($this->element). '_UPDATE', $user);
|
||||
$this->saveChild($user);
|
||||
|
||||
return true;
|
||||
}
|
||||
else{
|
||||
$this->error = $this->db->lasterror();
|
||||
|
||||
$this->saveChild($user);
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
return $this->id;
|
||||
@ -378,6 +389,9 @@ class CoreObject extends CommonObject {
|
||||
return $this->id;
|
||||
}
|
||||
else{
|
||||
|
||||
$this->error = $this->db->lasterror();
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@ -86,7 +86,7 @@ class Inventory extends CoreObject
|
||||
|
||||
}
|
||||
|
||||
private function sort_det()
|
||||
public function sort_det()
|
||||
{
|
||||
|
||||
if(!empty($this->Inventorydet)) usort($this->Inventorydet, array('Inventory', 'customSort'));
|
||||
@ -129,22 +129,23 @@ class Inventory extends CoreObject
|
||||
return $r;
|
||||
}
|
||||
|
||||
public function changePMP() {
|
||||
|
||||
foreach ($this->Inventorydet as $k => &$Inventorydet)
|
||||
{
|
||||
|
||||
if($Inventorydet->new_pmp>0) {
|
||||
$Inventorydet->pmp = $Inventorydet->new_pmp;
|
||||
$Inventorydet->new_pmp = 0;
|
||||
|
||||
$db->query("UPDATE ".MAIN_DB_PREFIX."product as p SET pmp = ".$Inventorydet->pmp."
|
||||
WHERE rowid = ".$Inventorydet->fk_product );
|
||||
public function changePMP(User &$user) {
|
||||
if(!empty($this->Inventorydet)) {
|
||||
foreach ($this->Inventorydet as $k => &$Inventorydet)
|
||||
{
|
||||
|
||||
if($Inventorydet->new_pmp>0) {
|
||||
$Inventorydet->pmp = $Inventorydet->new_pmp;
|
||||
$Inventorydet->new_pmp = 0;
|
||||
|
||||
$this->db->query("UPDATE ".MAIN_DB_PREFIX."product as p SET pmp = ".$Inventorydet->pmp."
|
||||
WHERE rowid = ".$Inventorydet->fk_product );
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
parent::save($PDOdb);
|
||||
return parent::update($user);
|
||||
|
||||
}
|
||||
|
||||
@ -214,6 +215,7 @@ class Inventory extends CoreObject
|
||||
if(empty($date))$date = $this->get_date('datec', 'Y-m-d');
|
||||
$det->setStockDate( $date , $fk_entrepot);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function correct_stock($fk_product, $fk_warehouse, $nbpiece, $movement, $label='', $price=0, $inventorycode='')
|
||||
@ -233,6 +235,9 @@ class Inventory extends CoreObject
|
||||
$datem = empty($conf->global->INVENTORY_USE_INVENTORY_DATE_FROM_DATEMVT) ? dol_now() : $this->date_inventory;
|
||||
|
||||
$movementstock=new MouvementStock($db);
|
||||
$movementstock->origin = new stdClass();
|
||||
$movementstock->origin->element = 'inventory';
|
||||
$movementstock->origin->id = $this->id;
|
||||
$result=$movementstock->_create($user,$fk_product,$fk_warehouse,$op[$movement],$movement,$price,$label,$inventorycode, $datem);
|
||||
|
||||
if ($result >= 0)
|
||||
@ -289,10 +294,7 @@ class Inventory extends CoreObject
|
||||
|
||||
$href = dol_buildpath('/inventory/inventory.php?id='.$this->id.'&action=view', 1);
|
||||
|
||||
if(empty($this->title))
|
||||
$this->correct_stock($product->id, $Inventorydet->fk_warehouse, $nbpiece, $movement, $langs->trans('inventoryMvtStock', $href, $this->id));
|
||||
else
|
||||
$this->correct_stock($product->id, $Inventorydet->fk_warehouse, $nbpiece, $movement, $langs->trans('inventoryMvtStockWithNomInventaire', $href, $this->title));
|
||||
$this->correct_stock($product->id, $Inventorydet->fk_warehouse, $nbpiece, $movement, $langs->trans('inventoryMvtStock'));
|
||||
}
|
||||
}
|
||||
|
||||
@ -304,12 +306,15 @@ class Inventory extends CoreObject
|
||||
return 1;
|
||||
}
|
||||
|
||||
public function getNomUrl($picto = 1) {
|
||||
public function getTitle() {
|
||||
global $langs;
|
||||
|
||||
$title = !empty($this->title) ? $this->title : $langs->trans('inventoryTitle').' '.$this->id;
|
||||
|
||||
return '<a href="'.dol_buildpath('/inventory/inventory.php?id='.$this->id, 1).'">'.($picto ? img_picto('','object_list.png','',0).' ' : '').$title.'</a>';
|
||||
return !empty($this->title) ? $this->title : $langs->trans('inventoryTitle').' '.$this->id;
|
||||
}
|
||||
|
||||
public function getNomUrl($picto = 1) {
|
||||
|
||||
return '<a href="'.dol_buildpath('/inventory/inventory.php?id='.$this->id, 1).'">'.($picto ? img_picto('','object_list.png','',0).' ' : '').$this->getTitle().'</a>';
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -77,16 +77,25 @@ function _action()
|
||||
$inventory->set_values($_POST);
|
||||
|
||||
$fk_inventory = $inventory->create($user);
|
||||
|
||||
$fk_category = (int)GETPOST('fk_category');
|
||||
$fk_supplier = (int)GETPOST('fk_supplier');
|
||||
$fk_warehouse = (int)GETPOST('fk_warehouse');
|
||||
$only_prods_in_stock = (int)GETPOST('OnlyProdsInStock');
|
||||
if($fk_inventory>0) {
|
||||
|
||||
$fk_category = (int)GETPOST('fk_category');
|
||||
$fk_supplier = (int)GETPOST('fk_supplier');
|
||||
$fk_warehouse = (int)GETPOST('fk_warehouse');
|
||||
$only_prods_in_stock = (int)GETPOST('OnlyProdsInStock');
|
||||
|
||||
$inventory->add_products_for($fk_warehouse,$fk_category,$fk_supplier,$only_prods_in_stock);
|
||||
$inventory->update($user);
|
||||
|
||||
header('Location: '.dol_buildpath('/inventory/inventory.php?id='.$inventory->id.'&action=edit', 1));
|
||||
|
||||
}
|
||||
else{
|
||||
|
||||
setEventMessage($inventory->error,'errors');
|
||||
header('Location: '.dol_buildpath('/inventory/inventory.php?action=create', 1));
|
||||
}
|
||||
|
||||
$inventory->add_products_for($fk_warehouse,$fk_category,$fk_supplier,$only_prods_in_stock);
|
||||
$inventory->update($user);
|
||||
|
||||
header('Location: '.dol_buildpath('inventory/inventory.php?id='.$inventory->id.'&action=edit', 1));
|
||||
break;
|
||||
|
||||
case 'edit':
|
||||
@ -118,14 +127,14 @@ function _action()
|
||||
}
|
||||
else
|
||||
{
|
||||
$inventory->save($PDOdb);
|
||||
$inventory->udpate($user);
|
||||
header('Location: '.dol_buildpath('inventory/inventory.php?id='.$inventory->getId().'&action=view', 1));
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case 'regulate':
|
||||
|
||||
case 'confirm_regulate':
|
||||
if (!$user->rights->inventory->write) accessforbidden();
|
||||
$id = GETPOST('id');
|
||||
|
||||
$inventory = new Inventory($db);
|
||||
@ -145,14 +154,14 @@ function _action()
|
||||
|
||||
break;
|
||||
|
||||
case 'changePMP':
|
||||
case 'confirm_changePMP':
|
||||
|
||||
$id = GETPOST('id');
|
||||
|
||||
$inventory = new Inventory($db);
|
||||
$inventory->fetch( $id );
|
||||
|
||||
$inventory->changePMP($PDOdb);
|
||||
$inventory->changePMP($user);
|
||||
|
||||
_card( $inventory, 'view');
|
||||
|
||||
@ -167,35 +176,33 @@ function _action()
|
||||
$inventory = new Inventory($db);
|
||||
$inventory->fetch( $id );
|
||||
|
||||
$type = (!empty($conf->use_javascript_ajax) && !empty($conf->global->PRODUIT_USE_SEARCH_TO_SELECT) ? 'string' : 'int'); //AA heu ?
|
||||
|
||||
$fk_product = __get('fk_product', 0, $type);
|
||||
|
||||
if ($fk_product)
|
||||
$fk_product = GETPOST('fk_product');
|
||||
if ($fk_product>0)
|
||||
{
|
||||
$product = new Product($db);
|
||||
$product->fetch($fk_product); // ! ref TODO vérifier quand même
|
||||
if($product->type != 0) {
|
||||
if($product->fetch($fk_product)<=0 || $product->type != 0) {
|
||||
setEventMessage($langs->trans('ThisIsNotAProduct'),'errors');
|
||||
}
|
||||
else{
|
||||
|
||||
//Check product not already exists
|
||||
$alreadyExists = false;
|
||||
foreach ($inventory->Inventorydet as $invdet)
|
||||
{
|
||||
if ($invdet->fk_product == $product->id
|
||||
&& $invdet->fk_warehouse == $fk_warehouse)
|
||||
if(!empty($inventory->Inventorydet)) {
|
||||
foreach ($inventory->Inventorydet as $invdet)
|
||||
{
|
||||
$alreadyExists = true;
|
||||
break;
|
||||
if ($invdet->fk_product == $product->id
|
||||
&& $invdet->fk_warehouse == $fk_warehouse)
|
||||
{
|
||||
$alreadyExists = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!$alreadyExists)
|
||||
{
|
||||
$inventory->add_product($PDOdb, $product->id, $fk_warehouse);
|
||||
|
||||
if($inventory->add_product($product->id, $fk_warehouse)) {
|
||||
setEventMessage($langs->trans('ProductAdded'));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -204,7 +211,7 @@ function _action()
|
||||
|
||||
}
|
||||
|
||||
$inventory->save($PDOdb);
|
||||
$inventory->update($user);
|
||||
$inventory->sort_det();
|
||||
}
|
||||
|
||||
@ -212,7 +219,7 @@ function _action()
|
||||
|
||||
break;
|
||||
|
||||
case 'delete_line':
|
||||
case 'confirm_delete_line':
|
||||
if (!$user->rights->inventory->write) accessforbidden();
|
||||
|
||||
|
||||
@ -230,7 +237,7 @@ function _action()
|
||||
_card($inventory, 'edit');
|
||||
|
||||
break;
|
||||
case 'flush':
|
||||
case 'confirm_flush':
|
||||
if (!$user->rights->inventory->create) accessforbidden();
|
||||
|
||||
|
||||
@ -239,15 +246,15 @@ function _action()
|
||||
$inventory = new Inventory($db);
|
||||
$inventory->fetch($id);
|
||||
|
||||
$inventory->deleteAllLine($PDOdb);
|
||||
$inventory->deleteAllLine($user);
|
||||
|
||||
setEventMessage('Inventaire vidé');
|
||||
setEventMessage($langs->trans('InventoryFlushed'));
|
||||
|
||||
_card( $inventory, 'edit');
|
||||
|
||||
|
||||
break;
|
||||
case 'delete':
|
||||
case 'confirm_delete':
|
||||
if (!$user->rights->inventory->create) accessforbidden();
|
||||
|
||||
|
||||
@ -258,7 +265,9 @@ function _action()
|
||||
|
||||
$inventory->delete($user);
|
||||
|
||||
header('Location: '.dol_buildpath('/inventory/inventory.php', 1));
|
||||
setEventMessage($langs->trans('InventoryDeleted'));
|
||||
|
||||
header('Location: '.dol_buildpath('/inventory/inventory.php?action=list', 1));
|
||||
exit;
|
||||
//_list();
|
||||
|
||||
@ -407,19 +416,53 @@ function _card_warehouse(&$inventory)
|
||||
llxFooter('');
|
||||
}
|
||||
|
||||
function _card(&$inventory, $mode='edit')
|
||||
function _card(&$inventory, $action='edit')
|
||||
{
|
||||
global $langs, $conf, $db, $user;
|
||||
global $langs, $conf, $db, $user,$form;
|
||||
|
||||
llxHeader('',$langs->trans('inventoryEdit'),'','');
|
||||
|
||||
if($action == 'changePMP') {
|
||||
|
||||
print $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$inventory->id,$langs->trans('ApplyNewPMP')
|
||||
,$langs->trans('ConfirmApplyNewPMP',$inventory->getTitle()),'confirm_changePMP'
|
||||
,array(),'no',1);
|
||||
|
||||
}
|
||||
else if($action == 'flush') {
|
||||
|
||||
print $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$inventory->id,$langs->trans('FlushInventory')
|
||||
,$langs->trans('ConfirmFlushInventory',$inventory->getTitle()),'confirm_flush'
|
||||
,array(),'no',1);
|
||||
|
||||
}
|
||||
else if($action == 'delete') {
|
||||
|
||||
print $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$inventory->id,$langs->trans('Delete')
|
||||
,$langs->trans('ConfirmDelete',$inventory->getTitle()),'confirm_delete'
|
||||
,array(),'no',1);
|
||||
|
||||
}
|
||||
else if($action == 'delete_line') {
|
||||
print $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$inventory->id.'&rowid='.GETPOST('rowid'),$langs->trans('DeleteLine')
|
||||
,$langs->trans('ConfirmDeleteLine',$inventory->getTitle()),'confirm_delete_line'
|
||||
,array(),'no',1);
|
||||
|
||||
}
|
||||
else if($action == 'regulate') {
|
||||
print $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$inventory->id,$langs->trans('RegulateStock')
|
||||
,$langs->trans('ConfirmRegulateStock',$inventory->getTitle()),'confirm_regulate'
|
||||
,array(),'no',1);
|
||||
|
||||
}
|
||||
|
||||
$warehouse = new Entrepot($db);
|
||||
$warehouse->fetch($inventory->fk_warehouse);
|
||||
|
||||
print dol_get_fiche_head(inventoryPrepareHead($inventory, $langs->trans('inventoryOfWarehouse', $warehouse->libelle), empty($mode) ? '': '&action='.$mode));
|
||||
print dol_get_fiche_head(inventoryPrepareHead($inventory, $langs->trans('inventoryOfWarehouse', $warehouse->libelle), empty($action) ? '': '&action='.$action));
|
||||
|
||||
$lines = array();
|
||||
_card_line($inventory, $lines, $mode);
|
||||
_card_line($inventory, $lines, $action);
|
||||
|
||||
print '<b>'.$langs->trans('inventoryOnDate')." ".$inventory->get_date('date_inventory').'</b><br><br>';
|
||||
|
||||
@ -439,7 +482,7 @@ function _card(&$inventory, $mode='edit')
|
||||
$view_url = dol_buildpath('/inventory/inventory.php', 1);
|
||||
|
||||
$view = array(
|
||||
'mode' => $mode
|
||||
'mode' => $action
|
||||
,'url' => dol_buildpath('/inventory/inventory.php', 1)
|
||||
,'can_validate' => (int) $user->rights->inventory->validate
|
||||
,'is_already_validate' => (int) $inventory->status
|
||||
@ -486,7 +529,7 @@ function _card_line(&$inventory, &$lines, $mode)
|
||||
,'qty_view' => $Inventorydet->qty_view ? $Inventorydet->qty_view : 0
|
||||
,'qty_stock' => $stock
|
||||
,'qty_regulated' => $Inventorydet->qty_regulated ? $Inventorydet->qty_regulated : 0
|
||||
,'action' => ($user->rights->inventory->write ? '<a onclick="if (!confirm(\'Confirmez-vous la suppression de la ligne ?\')) return false;" href="'.dol_buildpath('inventory/inventory.php?id='.$inventory->id.'&action=delete_line&rowid='.$Inventorydet->id, 1).'">'.img_picto($langs->trans('inventoryDeleteLine'), 'delete').'</a>' : '')
|
||||
,'action' => ($user->rights->inventory->write && $mode=='edit' ? '<a href="'.dol_buildpath('inventory/inventory.php?id='.$inventory->id.'&action=delete_line&rowid='.$Inventorydet->id, 1).'">'.img_picto($langs->trans('inventoryDeleteLine'), 'delete').'</a>' : '')
|
||||
,'pmp_stock'=>round($pmp_actual,2)
|
||||
,'pmp_actual'=> round($pmp * $Inventorydet->qty_view,2)
|
||||
,'pmp_new'=>(!empty($user->rights->inventory->changePMP && $mode =='edit') ? '<input type="text" name="new_pmp['.$k.']" value="'.$Inventorydet->new_pmp.'" size="8" style="text-align:right;" /> <a id="a_save_new_pmp_'.$k.'" href="javascript:save_pmp('.$k.')">'.img_picto($langs->trans('Save'), 'bt-save.png@inventory').'</a>' : price($Inventorydet->new_pmp))
|
||||
|
||||
@ -159,44 +159,40 @@
|
||||
}
|
||||
|
||||
_footerList($view,$total_pmp,$total_pmp_actual,$total_pa,$total_pa_actual, $total_current_pa,$total_current_pa_actual);
|
||||
?>
|
||||
|
||||
|
||||
|
||||
?>
|
||||
</table>
|
||||
|
||||
<?php if ($view['is_already_validate'] != 1) { ?>
|
||||
<?php if ($inventory->status != 1) { ?>
|
||||
<div class="tabsAction" style="height:30px;">
|
||||
<?php if ($view['mode'] == 'view') { ?>
|
||||
<?php if ($action!= 'edit') { ?>
|
||||
<a href="<?php echo $view_url; ?>?id=<?php echo $inventory->id; ?>&action=exportCSV" class="butAction"><?php echo $langs->trans('ExportCSV') ?></a>
|
||||
<a href="<?php echo $view_url; ?>?id=<?php echo $inventory->id; ?>&action=edit" class="butAction"><?php echo $langs->trans('Modify') ?></a>
|
||||
<?php
|
||||
if(!empty($user->rights->inventory->changePMP)) {
|
||||
echo '<a href="javascript:;" onclick="if (!confirm(\'Confirmez-vous l\\\'application du nouveau PMP ?\')) return false; else document.location.href=\''.$view_url
|
||||
.'?id='.$inventory->id
|
||||
.'&action=changePMP&token='.$view['token'].'\'; " class="butAction">'.$langs->trans('ApplyPMP').'</a>';
|
||||
echo '<a href="'.$view_url.'?id='.$inventory->id.'&action=changePMP" class="butAction">'.$langs->trans('ApplyPMP').'</a>';
|
||||
}
|
||||
|
||||
if ($can_validate == 1) { ?>
|
||||
<a href="javascript:;" onclick="if (!confirm('Confirmez-vous la régulation ?')) return false; else document.location.href='<?php echo $view_url; ?>?id=<?php echo $inventory->id; ?>&action=regulate&token=<?php echo $view['token']; ?>'; " class="butAction">Réguler le stock</a>
|
||||
<a href="<?php echo $view_url; ?>?id=<?php echo $inventory->id; ?>&action=regulate&token=" class="butAction"><?php echo $langs->trans('RegulateStock') ?></a>
|
||||
<?php } ?>
|
||||
<?php } ?>
|
||||
<?php if ($view['mode'] == 'edit') { ?>
|
||||
<input name="back" type="button" class="butAction" value="Quitter la saisie" onclick="document.location='?id=<?php echo $inventory->id; ?>&action=view';" />
|
||||
<?php if ($action == 'edit') { ?>
|
||||
<input name="back" type="button" class="butAction" value="<?php echo $langs->trans('ExitEditMode'); ?>" onclick="document.location='?id=<?php echo $inventory->id; ?>&action=view';" />
|
||||
<?php } ?>
|
||||
<?php if ($can_validate == 1) { ?>
|
||||
<a onclick="if (!confirm('Confirmez-vous la vidange ?')) return false;" href="<?php echo $view_url; ?>?id=<?php echo $inventory->id; ?>&action=flush" class="butActionDelete">Vider</a>
|
||||
<a href="<?php echo $view_url; ?>?id=<?php echo $inventory->id; ?>&action=flush" class="butActionDelete"><?php echo $langs->trans('Flush'); ?></a>
|
||||
|
||||
<a onclick="if (!confirm('Confirmez-vous la suppression ?')) return false;" href="<?php echo $view_url; ?>?id=<?php echo $inventory->id; ?>&action=delete" class="butActionDelete">Supprimer</a>
|
||||
<a href="<?php echo $view_url; ?>?id=<?php echo $inventory->id; ?>&action=delete" class="butActionDelete"><?php echo $langs->trans('Delete') ?></a>
|
||||
<?php } ?>
|
||||
</div>
|
||||
<?php } ?>
|
||||
<?php if ($view['is_already_validate'] == 1) { ?>
|
||||
<?php if ($inventory->status == 1) { ?>
|
||||
<div class="tabsAction">
|
||||
<?php if ($can_validate == 1) { ?>
|
||||
|
||||
<a href="<?php echo $view_url; ?>?id=<?php echo $inventory->id; ?>&action=exportCSV" class="butAction"><?php echo $langs->trans('ExportCSV') ?></a>
|
||||
<a href="#" title="Cet inventaire est validé" class="butActionRefused"><?php echo $langs->trans('Delete') ?></a>
|
||||
<a href="#" title="<?php echo $langs->trans('InventoryAlreadyValidated'); ?>" class="butActionRefused"><?php echo $langs->trans('Delete') ?></a>
|
||||
|
||||
<?php } ?>
|
||||
</div>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user