Skip to content

Commit

Permalink
Start to implement date selection of supplier proposals
Browse files Browse the repository at this point in the history
  • Loading branch information
eldy committed Sep 6, 2019
1 parent 123eace commit e1ee70f
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 58 deletions.
5 changes: 4 additions & 1 deletion htdocs/install/mysql/migration/10.0.0-11.0.0.sql
Expand Up @@ -105,4 +105,7 @@ create table llx_c_hrm_public_holiday
)ENGINE=innodb;



ALTER TABLE llx_supplier_proposaldet ADD COLUMN date_start datetime DEFAULT NULL;
ALTER TABLE llx_supplier_proposaldet ADD COLUMN date_end datetime DEFAULT NULL;


2 changes: 2 additions & 0 deletions htdocs/install/mysql/tables/llx_supplier_proposaldet.sql
Expand Up @@ -40,6 +40,8 @@ CREATE TABLE llx_supplier_proposaldet (
total_localtax2 double(24,8) DEFAULT 0,
total_ttc double(24,8) DEFAULT 0,
product_type integer DEFAULT 0,
date_start datetime DEFAULT NULL, -- date debut si service
date_end datetime DEFAULT NULL, -- date fin si service
info_bits integer DEFAULT 0,
buy_price_ht double(24,8) DEFAULT 0,
fk_product_fournisseur_price integer DEFAULT NULL,
Expand Down
21 changes: 16 additions & 5 deletions htdocs/supplier_proposal/card.php
Expand Up @@ -357,7 +357,7 @@
$array_options = $lines[$i]->array_options;
}

$result = $object->addline(
$result = $object->addline(
$desc, $lines[$i]->subprice, $lines[$i]->qty, $lines[$i]->tva_tx,
$lines[$i]->localtax1_tx, $lines[$i]->localtax2_tx,
$lines[$i]->fk_product, $lines[$i]->remise_percent,
Expand Down Expand Up @@ -646,6 +646,9 @@
$pu_ht = $productsupplier->fourn_pu;
if (empty($pu_ht)) $pu_ht = 0; // If pu is '' or null, we force to have a numeric value

$fournprice = 0;
$buyingprice = 0;

$result=$object->addline(
$desc,
$pu_ht,
Expand All @@ -670,9 +673,17 @@
$productsupplier->fk_unit,
'',
0,
$productsupplier->fourn_multicurrency_unitprice
$productsupplier->fourn_multicurrency_unitprice,
$date_start,
$date_end
);

//var_dump($tva_tx);var_dump($productsupplier->fourn_pu);var_dump($price_base_type);exit;
if ($result < 0)
{
$error++;
setEventMessages($object->error, $object->errors, 'errors');
}
}
if ($idprod == -99 || $idprod == 0)
{
Expand Down Expand Up @@ -1751,20 +1762,20 @@

// Add free products/services form
global $forceall, $senderissupplier, $dateSelector, $inputalsopricewithtax;
$forceall=1; $dateSelector=0; $inputalsopricewithtax=1;
$forceall=1; $dateSelector=1; $inputalsopricewithtax=1;
$senderissupplier=2; // $senderissupplier=2 is same than 1 but disable test on minimum qty.
if (! empty($conf->global->SUPPLIER_PROPOSAL_WITH_PREDEFINED_PRICES_ONLY)) $senderissupplier=1;

if (! empty($object->lines))
$ret = $object->printObjectLines($action, $soc, $mysoc, $lineid, 1);
$ret = $object->printObjectLines($action, $soc, $mysoc, $lineid, $dateSelector);

// Form to add new line
if ($object->statut == SupplierProposal::STATUS_DRAFT && $user->rights->supplier_proposal->creer)
{
if ($action != 'editline')
{
// Add products/services form
$object->formAddObjectLine(1, $soc, $mysoc);
$object->formAddObjectLine($dateSelector, $soc, $mysoc);

$parameters = array();
$reshook = $hookmanager->executeHooks('formAddObjectLine', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
Expand Down
83 changes: 31 additions & 52 deletions htdocs/supplier_proposal/class/supplier_proposal.class.php
Expand Up @@ -391,11 +391,13 @@ public function insert_discount($idremise)
* @param string $origin 'order', 'supplier_proposal', ...
* @param int $origin_id Id of origin line
* @param double $pu_ht_devise Amount in currency
* @param int $date_start Date start
* @param int $date_end Date end
* @return int >0 if OK, <0 if KO
*
* @see add_product()
*/
public function addline($desc, $pu_ht, $qty, $txtva, $txlocaltax1 = 0, $txlocaltax2 = 0, $fk_product = 0, $remise_percent = 0, $price_base_type = 'HT', $pu_ttc = 0, $info_bits = 0, $type = 0, $rang = -1, $special_code = 0, $fk_parent_line = 0, $fk_fournprice = 0, $pa_ht = 0, $label = '', $array_option = 0, $ref_supplier = '', $fk_unit = '', $origin = '', $origin_id = 0, $pu_ht_devise = 0)
public function addline($desc, $pu_ht, $qty, $txtva, $txlocaltax1 = 0, $txlocaltax2 = 0, $fk_product = 0, $remise_percent = 0, $price_base_type = 'HT', $pu_ttc = 0, $info_bits = 0, $type = 0, $rang = -1, $special_code = 0, $fk_parent_line = 0, $fk_fournprice = 0, $pa_ht = 0, $label = '', $array_option = 0, $ref_supplier = '', $fk_unit = '', $origin = '', $origin_id = 0, $pu_ht_devise = 0, $date_start = 0, $date_end = 0)
{
global $mysoc, $conf;

Expand Down Expand Up @@ -570,6 +572,8 @@ public function addline($desc, $pu_ht, $qty, $txtva, $txlocaltax1 = 0, $txlocalt
$this->line->origin=$origin;
$this->line->origin_id=$origin_id;
$this->line->ref_fourn = $this->db->escape($ref_supplier);
$this->line->date_start = $date_start;
$this->line->date_end = $date_end;

// infos marge
if (!empty($fk_product) && empty($fk_fournprice) && empty($pa_ht)) {
Expand All @@ -594,10 +598,6 @@ public function addline($desc, $pu_ht, $qty, $txtva, $txlocaltax1 = 0, $txlocalt
// Mise en option de la ligne
if (empty($qty) && empty($special_code)) $this->line->special_code=3;

// TODO deprecated
$this->line->price=$price;
$this->line->remise=$remise;

if (is_array($array_option) && count($array_option)>0) {
$this->line->array_options=$array_option;
}
Expand All @@ -613,7 +613,7 @@ public function addline($desc, $pu_ht, $qty, $txtva, $txlocaltax1 = 0, $txlocalt
if ($result > 0)
{
$this->db->commit();
return $this->line->rowid;
return $this->line->id;
}
else
{
Expand All @@ -629,6 +629,11 @@ public function addline($desc, $pu_ht, $qty, $txtva, $txlocaltax1 = 0, $txlocalt
return -2;
}
}
else
{
$this->error = 'BadStatusOfObjectToAddLine';
return -5;
}
}


Expand Down Expand Up @@ -688,6 +693,7 @@ public function updateline($rowid, $pu, $qty, $remise_percent, $txtva, $txlocalt
$localtaxes_type=getLocalTaxesFromRate($txtva, 0, $mysoc, $this->thirdparty);

// Clean vat code
$reg = array();
$vat_src_code='';
if (preg_match('/\((.*)\)/', $txtva, $reg))
{
Expand All @@ -707,14 +713,6 @@ public function updateline($rowid, $pu, $qty, $remise_percent, $txtva, $txlocalt
$multicurrency_total_tva = $tabprice[17];
$multicurrency_total_ttc = $tabprice[18];

// Anciens indicateurs: $price, $remise (a ne plus utiliser)
$price = $pu;
if ($remise_percent > 0)
{
$remise = round(($pu * $remise_percent / 100), 2);
$price = $pu - $remise;
}

// Update line
$this->line=new SupplierProposalLine($this->db);

Expand All @@ -730,7 +728,7 @@ public function updateline($rowid, $pu, $qty, $remise_percent, $txtva, $txlocalt
$this->line->rang = $rangmax + 1;
}

$this->line->rowid = $rowid;
$this->line->id = $rowid;
$this->line->label = $label;
$this->line->desc = $desc;
$this->line->qty = $qty;
Expand Down Expand Up @@ -768,10 +766,6 @@ public function updateline($rowid, $pu, $qty, $remise_percent, $txtva, $txlocalt
}
$this->line->pa_ht = $pa_ht;

// TODO deprecated
$this->line->price=$price;
$this->line->remise=$remise;

if (is_array($array_option) && count($array_option)>0) {
$this->line->array_options=$array_option;
}
Expand All @@ -791,7 +785,6 @@ public function updateline($rowid, $pu, $qty, $remise_percent, $txtva, $txlocalt
$this->update_price(1);

$this->fk_supplier_proposal = $this->id;
$this->rowid = $rowid;

$this->db->commit();
return $result;
Expand Down Expand Up @@ -2745,9 +2738,6 @@ class SupplierProposalLine extends CommonObjectLine

public $oldline;

// From llx_supplier_proposaldet
public $rowid; // deprecated

/**
* @var int ID
*/
Expand Down Expand Up @@ -2813,20 +2803,11 @@ class SupplierProposalLine extends CommonObjectLine
// Bit 1: 0 ligne normale - 1 si ligne de remise fixe

public $total_ht; // Total HT de la ligne toute quantite et incluant la remise ligne
public $total_tva; // Total TVA de la ligne toute quantite et incluant la remise ligne
public $total_tva; // Total TVA de la ligne toute quantite et incluant la remise ligne
public $total_ttc; // Total TTC de la ligne toute quantite et incluant la remise ligne

/**
* @deprecated
* @see remise_percent, fk_remise_except
*/
public $remise;

/**
* @deprecated
* @see subprice
*/
public $price;
public $date_start;
public $date_end;

// From llx_product
/**
Expand Down Expand Up @@ -2902,6 +2883,7 @@ public function __construct($db)
public function fetch($rowid)
{
$sql = 'SELECT pd.rowid, pd.fk_supplier_proposal, pd.fk_parent_line, pd.fk_product, pd.label as custom_label, pd.description, pd.price, pd.qty, pd.tva_tx,';
$sql.= ' pd.date_start, pd.date_end,';
$sql.= ' pd.remise, pd.remise_percent, pd.fk_remise_except, pd.subprice,';
$sql.= ' pd.info_bits, pd.total_ht, pd.total_tva, pd.total_ttc, pd.fk_product_fournisseur_price as fk_fournprice, pd.buy_price_ht as pa_ht, pd.special_code, pd.rang,';
$sql.= ' pd.localtax1_tx, pd.localtax2_tx, pd.total_localtax1, pd.total_localtax2,';
Expand All @@ -2917,21 +2899,20 @@ public function fetch($rowid)
{
$objp = $this->db->fetch_object($result);

$this->rowid = $objp->rowid; // deprecated
$this->id = $objp->rowid;
$this->fk_supplier_proposal = $objp->fk_supplier_proposal;
$this->fk_parent_line = $objp->fk_parent_line;
$this->label = $objp->custom_label;
$this->desc = $objp->description;
$this->qty = $objp->qty;
$this->price = $objp->price; // deprecated
$this->subprice = $objp->subprice;
$this->tva_tx = $objp->tva_tx;
$this->remise = $objp->remise;
$this->remise_percent = $objp->remise_percent;
$this->fk_remise_except = $objp->fk_remise_except;
$this->fk_product = $objp->fk_product;
$this->info_bits = $objp->info_bits;
$this->date_start = $this->db->jdate($objp->date_start);
$this->date_end = $this->db->jdate($objp->date_end);

$this->total_ht = $objp->total_ht;
$this->total_tva = $objp->total_tva;
Expand Down Expand Up @@ -3028,6 +3009,7 @@ public function insert($notrigger = 0)
// Insert line into database
$sql = 'INSERT INTO '.MAIN_DB_PREFIX.'supplier_proposaldet';
$sql.= ' (fk_supplier_proposal, fk_parent_line, label, description, fk_product, product_type,';
$sql.= ' date_start, date_end,';
$sql.= ' fk_remise_except, qty, tva_tx, localtax1_tx, localtax2_tx, localtax1_type, localtax2_type,';
$sql.= ' subprice, remise_percent, ';
$sql.= ' info_bits, ';
Expand All @@ -3040,6 +3022,8 @@ public function insert($notrigger = 0)
$sql.= " '".$this->db->escape($this->desc)."',";
$sql.= " ".($this->fk_product?"'".$this->db->escape($this->fk_product)."'":"null").",";
$sql.= " '".$this->db->escape($this->product_type)."',";
$sql.= " ".($this->date_start ? "'".$this->db->idate($this->date_start)."'" : "null").",";
$sql.= " ".($this->date_end ? "'".$this->db->idate($this->date_end)."'" : "null").",";
$sql.= " ".($this->fk_remise_except?"'".$this->db->escape($this->fk_remise_except)."'":"null").",";
$sql.= " ".price2num($this->qty).",";
$sql.= " ".price2num($this->tva_tx).",";
Expand Down Expand Up @@ -3073,8 +3057,7 @@ public function insert($notrigger = 0)
$resql=$this->db->query($sql);
if ($resql)
{
$this->rowid=$this->db->last_insert_id(MAIN_DB_PREFIX.'supplier_proposaldet');
$this->id=$this->rowid;
$this->id=$this->db->last_insert_id(MAIN_DB_PREFIX.'supplier_proposaldet');

if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used
{
Expand Down Expand Up @@ -3120,15 +3103,14 @@ public function delete()
$error=0;
$this->db->begin();

$sql = "DELETE FROM ".MAIN_DB_PREFIX."supplier_proposaldet WHERE rowid = ".$this->rowid;
$sql = "DELETE FROM ".MAIN_DB_PREFIX."supplier_proposaldet WHERE rowid = ".$this->id;
dol_syslog("SupplierProposalLine::delete", LOG_DEBUG);
if ($this->db->query($sql) )
{

// Remove extrafields
if ((! $error) && (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED))) // For avoid conflicts if trigger used
{
$this->id=$this->rowid;
$result=$this->deleteExtraFields();
if ($result < 0)
{
Expand Down Expand Up @@ -3180,8 +3162,6 @@ public function update($notrigger = 0)
if (empty($this->localtax2_type)) $this->localtax2_type=0;
if (empty($this->marque_tx)) $this->marque_tx=0;
if (empty($this->marge_tx)) $this->marge_tx=0;
if (empty($this->price)) $this->price=0; // TODO A virer
if (empty($this->remise)) $this->remise=0; // TODO A virer
if (empty($this->remise_percent)) $this->remise_percent=0;
if (empty($this->info_bits)) $this->info_bits=0;
if (empty($this->special_code)) $this->special_code=0;
Expand Down Expand Up @@ -3212,6 +3192,8 @@ public function update($notrigger = 0)
$sql.= " description='".$this->db->escape($this->desc)."'";
$sql.= " , label=".(! empty($this->label)?"'".$this->db->escape($this->label)."'":"null");
$sql.= " , product_type=".$this->product_type;
$sql.= " , date_start=".($this->date_start ? "'".$this->db->idate($this->date_start)."'" : "null");
$sql.= " , date_end=".($this->date_end ? "'".$this->db->idate($this->date_end)."'" : "null");
$sql.= " , tva_tx='".price2num($this->tva_tx)."'";
$sql.= " , localtax1_tx=".price2num($this->localtax1_tx);
$sql.= " , localtax2_tx=".price2num($this->localtax2_tx);
Expand All @@ -3220,8 +3202,6 @@ public function update($notrigger = 0)
$sql.= " , qty='".price2num($this->qty)."'";
$sql.= " , subprice=".price2num($this->subprice)."";
$sql.= " , remise_percent=".price2num($this->remise_percent)."";
$sql.= " , price=".price2num($this->price).""; // TODO A virer
$sql.= " , remise=".price2num($this->remise).""; // TODO A virer
$sql.= " , info_bits='".$this->db->escape($this->info_bits)."'";
if (empty($this->skip_update_total))
{
Expand All @@ -3245,15 +3225,14 @@ public function update($notrigger = 0)
$sql.= " , multicurrency_total_tva=".price2num($this->multicurrency_total_tva)."";
$sql.= " , multicurrency_total_ttc=".price2num($this->multicurrency_total_ttc)."";

$sql.= " WHERE rowid = ".$this->rowid;
$sql.= " WHERE rowid = ".$this->id;

dol_syslog(get_class($this)."::update", LOG_DEBUG);
$resql=$this->db->query($sql);
if ($resql)
{
if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used
{
$this->id=$this->rowid;
$result=$this->insertExtraFields();
if ($result < 0)
{
Expand Down Expand Up @@ -3298,10 +3277,10 @@ public function update_total()

// Mise a jour ligne en base
$sql = "UPDATE ".MAIN_DB_PREFIX."supplier_proposaldet SET";
$sql.= " total_ht=".price2num($this->total_ht, 'MT')."";
$sql.= ",total_tva=".price2num($this->total_tva, 'MT')."";
$sql.= ",total_ttc=".price2num($this->total_ttc, 'MT')."";
$sql.= " WHERE rowid = ".$this->rowid;
$sql.= " total_ht=".price2num($this->total_ht, 'MT');
$sql.= ",total_tva=".price2num($this->total_tva, 'MT');
$sql.= ",total_ttc=".price2num($this->total_ttc, 'MT');
$sql.= " WHERE rowid = ".$this->id;

dol_syslog("SupplierProposalLine::update_total", LOG_DEBUG);

Expand Down

0 comments on commit e1ee70f

Please sign in to comment.