Uniformize code and add more comment to understand workflow

This commit is contained in:
Laurent Destailleur 2016-04-26 13:27:32 +02:00
parent 714b5556f3
commit 66ea799eb7
4 changed files with 46 additions and 8 deletions

View File

@ -533,6 +533,12 @@ if (empty($reshook))
$object->set_billed(); $object->set_billed();
} }
elseif ($action == 'classifyclosed')
{
$object->fetch($id);
$object->setClosed();
}
include DOL_DOCUMENT_ROOT.'/core/actions_printing.inc.php'; include DOL_DOCUMENT_ROOT.'/core/actions_printing.inc.php';
// Actions to send emails // Actions to send emails
@ -1780,10 +1786,14 @@ else if ($id || $ref)
{ {
if ($user->rights->expedition->creer && $object->statut > 0 && ! $object->billed) if ($user->rights->expedition->creer && $object->statut > 0 && ! $object->billed)
{ {
$label="Close"; // = Transferred/Received $label="Close"; $paramaction='classifyclosed'; // = Transferred/Received
// Label here should be "Close" or "ClassifyBilled" if we decided to make bill on shipments instead of orders // Label here should be "Close" or "ClassifyBilled" if we decided to make bill on shipments instead of orders
if (! empty($conf->global->WORKFLOW_BILL_ON_SHIPMENT)) $label="ClassifyBilled"; if (! empty($conf->global->WORKFLOW_BILL_ON_SHIPMENT)) // TODO Quand l'option est on, il faut avoir le bouton en plus et non en remplacement du Close.
print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=classifybilled">'.$langs->trans($label).'</a>'; {
$label="ClassifyBilled";
$paramaction='classifybilled';
}
print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action='.$paramaction.'">'.$langs->trans($label).'</a>';
} }
} }

View File

@ -1795,11 +1795,11 @@ class Expedition extends CommonObject
} }
/** /**
* Classify the shipping as invoiced * Classify the shipping as closed
* *
* @return int <0 if ko, >0 if ok * @return int <0 if ko, >0 if ok
*/ */
function set_billed() function setClosed()
{ {
global $conf; global $conf;
@ -1809,7 +1809,32 @@ class Expedition extends CommonObject
$resql=$this->db->query($sql); $resql=$this->db->query($sql);
if ($resql) if ($resql)
{ {
//TODO: Add option/checkbox to set order billed if 100% of order is shipped // TODO: Add option/checkbox to set order billed if 100% of order is shipped
$this->statut=2;
return 1;
}
else
{
dol_print_error($this->db);
return -1;
}
}
/**
* Classify the shipping as invoiced (used when WORKFLOW_BILL_ON_SHIPMENT is on)
*
* @return int <0 if ko, >0 if ok
*/
function set_billed()
{
global $conf;
$sql = 'UPDATE '.MAIN_DB_PREFIX.'expedition SET fk_statut=2, billed=1'; // TODO Update only billed
$sql .= ' WHERE rowid = '.$this->id.' AND fk_statut > 0';
$resql=$this->db->query($sql);
if ($resql)
{
$this->statut=2; $this->statut=2;
$this->billed=1; $this->billed=1;
return 1; return 1;

View File

@ -36,6 +36,8 @@ ALTER TABLE llx_product_customer_price_log ADD COLUMN localtax1_type varchar(10)
ALTER TABLE llx_product_customer_price_log ADD COLUMN localtax2_type varchar(10) NOT NULL DEFAULT '0' after localtax2_tx; ALTER TABLE llx_product_customer_price_log ADD COLUMN localtax2_type varchar(10) NOT NULL DEFAULT '0' after localtax2_tx;
ALTER TABLE llx_expedition ADD COLUMN billed smallint DEFAULT 0;
CREATE TABLE llx_product_lot ( CREATE TABLE llx_product_lot (
rowid integer AUTO_INCREMENT PRIMARY KEY, rowid integer AUTO_INCREMENT PRIMARY KEY,
tms timestamp, tms timestamp,

View File

@ -40,7 +40,8 @@ create table llx_expedition
fk_address integer DEFAULT NULL, -- delivery address (deprecated) fk_address integer DEFAULT NULL, -- delivery address (deprecated)
fk_shipping_method integer, fk_shipping_method integer,
tracking_number varchar(50), tracking_number varchar(50),
fk_statut smallint DEFAULT 0, fk_statut smallint DEFAULT 0, -- 0 = draft, 1 = validated, 2 = billed or closed depending on WORKFLOW_BILL_ON_SHIPMENT option
billed smallint DEFAULT 0,
height float, -- height height float, -- height
width float, -- with width float, -- with