[CORE] Avancement du fonctionnement du module, correction bug et épuration de l'affichage (#new_ask_price).

This commit is contained in:
phf 2015-02-02 15:41:14 +01:00
parent 5573c6a250
commit a3c29f2e9c
6 changed files with 135 additions and 60 deletions

View File

@ -249,18 +249,12 @@ if (empty($reshook))
$datep = dol_mktime(12, 0, 0, GETPOST('remonth'), GETPOST('reday'), GETPOST('reyear')); $datep = dol_mktime(12, 0, 0, GETPOST('remonth'), GETPOST('reday'), GETPOST('reyear'));
$date_delivery = dol_mktime(12, 0, 0, GETPOST('liv_month'), GETPOST('liv_day'), GETPOST('liv_year')); $date_delivery = dol_mktime(12, 0, 0, GETPOST('liv_month'), GETPOST('liv_day'), GETPOST('liv_year'));
$duration = GETPOST('duree_validite');
if (empty($datep)) { if (empty($datep)) {
setEventMessage($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Date")), 'errors'); setEventMessage($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Date")), 'errors');
$action = 'create'; $action = 'create';
$error ++; $error ++;
} }
if (empty($duration)) {
setEventMessage($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("ValidityDuration")), 'errors');
$action = 'create';
$error ++;
}
if ($socid < 1) { if ($socid < 1) {
setEventMessage($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Customer")), 'errors'); setEventMessage($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Customer")), 'errors');
@ -969,7 +963,7 @@ if (empty($reshook))
} }
} }
else if ($action == 'updateligne' && $user->rights->propal->creer && GETPOST('cancel') == $langs->trans('Cancel')) { else if ($action == 'updateligne' && $user->rights->askpricesupplier->creer && GETPOST('cancel') == $langs->trans('Cancel')) {
header('Location: ' . $_SERVER['PHP_SELF'] . '?id=' . $object->id); // Pour reaffichage de la fiche en cours d'edition header('Location: ' . $_SERVER['PHP_SELF'] . '?id=' . $object->id); // Pour reaffichage de la fiche en cours d'edition
exit(); exit();
} }
@ -1664,6 +1658,7 @@ if ($action == 'create')
print '</td></tr>'; print '</td></tr>';
// Ref customer // Ref customer
/* PHFAVRE retrait en temporaire
print '<tr><td>'; print '<tr><td>';
print '<table class="nobordernopadding" width="100%"><tr><td class="nowrap">'; print '<table class="nobordernopadding" width="100%"><tr><td class="nowrap">';
print $langs->trans('RefCustomer') . '</td>'; print $langs->trans('RefCustomer') . '</td>';
@ -1684,12 +1679,14 @@ if ($action == 'create')
} }
print '</td>'; print '</td>';
print '</tr>'; print '</tr>';
*/
// Company // Company
print '<tr><td>' . $langs->trans('Company') . '</td><td colspan="5">' . $soc->getNomUrl(1) . '</td>'; print '<tr><td>' . $langs->trans('Supplier') . '</td><td colspan="5">' . $soc->getNomUrl(1) . '</td>';
print '</tr>'; print '</tr>';
// Ligne info remises tiers // Ligne info remises tiers
/* PHFAVRE retrait en temporaire
print '<tr><td>' . $langs->trans('Discounts') . '</td><td colspan="5">'; print '<tr><td>' . $langs->trans('Discounts') . '</td><td colspan="5">';
if ($soc->remise_percent) if ($soc->remise_percent)
print $langs->trans("CompanyHasRelativeDiscount", $soc->remise_percent); print $langs->trans("CompanyHasRelativeDiscount", $soc->remise_percent);
@ -1716,6 +1713,7 @@ if ($action == 'create')
if (! $absolute_discount && ! $absolute_creditnote) if (! $absolute_discount && ! $absolute_creditnote)
print $langs->trans("CompanyHasNoAbsoluteDiscount") . '.'; print $langs->trans("CompanyHasNoAbsoluteDiscount") . '.';
print '</td></tr>'; print '</td></tr>';
*/
// Date of proposal // Date of proposal
print '<tr>'; print '<tr>';
@ -1744,6 +1742,7 @@ if ($action == 'create')
print '</td>'; print '</td>';
// Date end proposal // Date end proposal
/* PHFAVRE retrait en temporaire
print '<tr>'; print '<tr>';
print '<td>'; print '<td>';
print '<table class="nobordernopadding" width="100%"><tr><td>'; print '<table class="nobordernopadding" width="100%"><tr><td>';
@ -1771,6 +1770,7 @@ if ($action == 'create')
} }
print '</td>'; print '</td>';
print '</tr>'; print '</tr>';
*/
// Payment term // Payment term
print '<tr><td>'; print '<tr><td>';
@ -1790,6 +1790,7 @@ if ($action == 'create')
print '</tr>'; print '</tr>';
// Delivery date // Delivery date
/* PHFAVRE retrait en temporaire
$langs->load('deliveries'); $langs->load('deliveries');
print '<tr><td>'; print '<tr><td>';
print '<table class="nobordernopadding" width="100%"><tr><td>'; print '<table class="nobordernopadding" width="100%"><tr><td>';
@ -1811,8 +1812,10 @@ if ($action == 'create')
} }
print '</td>'; print '</td>';
print '</tr>'; print '</tr>';
*/
// Delivery delay // Delivery delay
/* PHFAVRE retrait en temporaire
print '<tr><td>'; print '<tr><td>';
print '<table class="nobordernopadding" width="100%"><tr><td>'; print '<table class="nobordernopadding" width="100%"><tr><td>';
print $langs->trans('AvailabilityPeriod'); print $langs->trans('AvailabilityPeriod');
@ -1831,8 +1834,10 @@ if ($action == 'create')
print '</td>'; print '</td>';
print '</tr>'; print '</tr>';
*/
// Shipping Method // Shipping Method
/* PHFAVRE retrait en temporaire
if (! empty($conf->expedition->enabled)) { if (! empty($conf->expedition->enabled)) {
print '<tr><td>'; print '<tr><td>';
print '<table width="100%" class="nobordernopadding"><tr><td>'; print '<table width="100%" class="nobordernopadding"><tr><td>';
@ -1850,8 +1855,10 @@ if ($action == 'create')
print '</td>'; print '</td>';
print '</tr>'; print '</tr>';
} }
*/
// Origin of demand // Origin of demand
/* PHFAVRE retrait en temporaire
print '<tr><td>'; print '<tr><td>';
print '<table class="nobordernopadding" width="100%"><tr><td>'; print '<table class="nobordernopadding" width="100%"><tr><td>';
print $langs->trans('Source'); print $langs->trans('Source');
@ -1867,6 +1874,7 @@ if ($action == 'create')
} }
print '</td>'; print '</td>';
print '</tr>'; print '</tr>';
*/
// Payment mode // Payment mode
print '<tr>'; print '<tr>';
@ -1886,6 +1894,7 @@ if ($action == 'create')
print '</td></tr>'; print '</td></tr>';
// Project // Project
/*
if (! empty($conf->projet->enabled)) { if (! empty($conf->projet->enabled)) {
$langs->load("projects"); $langs->load("projects");
print '<tr><td>'; print '<tr><td>';
@ -1918,6 +1927,7 @@ if ($action == 'create')
} }
print '</tr>'; print '</tr>';
} }
*/
if ($soc->outstanding_limit) if ($soc->outstanding_limit)
{ {
@ -1938,7 +1948,7 @@ if ($action == 'create')
print '<table width="100%" class="nobordernopadding"><tr><td>'; print '<table width="100%" class="nobordernopadding"><tr><td>';
print $langs->trans('BankAccount'); print $langs->trans('BankAccount');
print '</td>'; print '</td>';
if ($action != 'editbankaccount' && $user->rights->propal->creer) if ($action != 'editbankaccount' && $user->rights->askpricesupplier->creer)
print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editbankaccount&amp;id='.$object->id.'">'.img_edit($langs->trans('SetBankAccount'),1).'</a></td>'; print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editbankaccount&amp;id='.$object->id.'">'.img_edit($langs->trans('SetBankAccount'),1).'</a></td>';
print '</tr></table>'; print '</tr></table>';
print '</td><td colspan="3">'; print '</td><td colspan="3">';
@ -2033,6 +2043,7 @@ if ($action == 'create')
$ret = $object->printObjectLines($action, $mysoc, $soc, $lineid, 1); $ret = $object->printObjectLines($action, $mysoc, $soc, $lineid, 1);
// Form to add new line // Form to add new line
/* PHFAVRE retrait en temporaire*/
if ($object->statut == 0 && $user->rights->askpricesupplier->creer) if ($object->statut == 0 && $user->rights->askpricesupplier->creer)
{ {
if ($action != 'editline') if ($action != 'editline')
@ -2047,6 +2058,24 @@ if ($action == 'create')
} }
} }
/*
// Form to add new line
if ($object->statut == 0 && $user->rights->askpricesupplier->creer)
{
// Add free products/services form
global $forceall, $senderissupplier, $dateSelector;
$forceall=1; $senderissupplier=1; $dateSelector=0;
$var = true;
// Add free products/services
$object->formAddObjectLine(1, $mysoc, $object);
$parameters = array();
$reshook = $hookmanager->executeHooks('formAddObjectLine', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
}
*/
print '</table>'; print '</table>';
print "</form>\n"; print "</form>\n";
@ -2065,8 +2094,8 @@ if ($action == 'create')
$form_close .= '<input type="hidden" name="action" value="setstatut">'; $form_close .= '<input type="hidden" name="action" value="setstatut">';
$form_close .= '<select id="statut" name="statut" class="flat">'; $form_close .= '<select id="statut" name="statut" class="flat">';
$form_close .= '<option value="0">&nbsp;</option>'; $form_close .= '<option value="0">&nbsp;</option>';
$form_close .= '<option value="2">' . $object->labelstatut [2] . '</option>'; $form_close .= '<option value="2">' . $langs->trans('AskpricesupplierStatusSigned') . '</option>';
$form_close .= '<option value="3">' . $object->labelstatut [3] . '</option>'; $form_close .= '<option value="3">' . $langs->trans('AskpricesupplierStatusNotSigned') . '</option>';
$form_close .= '</select>'; $form_close .= '</select>';
$form_close .= '</td></tr>'; $form_close .= '</td></tr>';
$form_close .= '<tr><td width="150" align="left">' . $langs->trans('Note') . '</td><td align="left"><textarea cols="70" rows="' . ROWS_3 . '" wrap="soft" name="note">'; $form_close .= '<tr><td width="150" align="left">' . $langs->trans('Note') . '</td><td align="left"><textarea cols="70" rows="' . ROWS_3 . '" wrap="soft" name="note">';
@ -2097,7 +2126,7 @@ if ($action == 'create')
{ {
// Validate // Validate
if ($object->statut == 0 && $object->total_ttc >= 0 && count($object->lines) > 0 && if ($object->statut == 0 && $object->total_ttc >= 0 && count($object->lines) > 0 &&
((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->propal->creer)) ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->askpricesupplier->creer))
|| (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->askpricesupplier->validate))) || (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->askpricesupplier->validate)))
) { ) {
if (count($object->lines) > 0) if (count($object->lines) > 0)
@ -2211,7 +2240,7 @@ if ($action == 'create')
// List of actions on element // List of actions on element
include_once DOL_DOCUMENT_ROOT . '/core/class/html.formactions.class.php'; include_once DOL_DOCUMENT_ROOT . '/core/class/html.formactions.class.php';
$formactions = new FormActions($db); $formactions = new FormActions($db);
$somethingshown = $formactions->showactions($object, 'propal', $socid); $somethingshown = $formactions->showactions($object, 'askpricesupplier', $socid);
// print '</td></tr></table>'; // print '</td></tr></table>';
print '</div></div></div>'; print '</div></div></div>';
@ -2226,7 +2255,7 @@ if ($action == 'create')
$ref = dol_sanitizeFileName($object->ref); $ref = dol_sanitizeFileName($object->ref);
include_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php'; include_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php';
$fileparams = dol_most_recent_file($conf->propal->dir_output . '/' . $ref, preg_quote($ref, '/')); $fileparams = dol_most_recent_file($conf->askpricesupplier->dir_output . '/' . $ref, preg_quote($ref, '/'));
$file = $fileparams ['fullname']; $file = $fileparams ['fullname'];
// Define output language // Define output language

View File

@ -1787,7 +1787,7 @@ class AskPriceSupplier extends CommonObject
} }
else else
{ {
$this->updatePriceFournisseur(); $this->updateOrCreatePriceFournisseur($user);
} }
} }
if ($statut == 4) if ($statut == 4)
@ -1833,21 +1833,46 @@ class AskPriceSupplier extends CommonObject
} }
} }
function updatePriceFournisseur() /**
* Choose between upate or create ProductFournisseur
*
* @param User $user Object user
* @return int <0 if KO, >0 if OK
*/
function updateOrCreatePriceFournisseur($user)
{ {
$productsupplier = new ProductFournisseur($this->db); $productsupplier = new ProductFournisseur($this->db);
dol_syslog(get_class($this)."::updatePriceFournisseur", LOG_DEBUG); dol_syslog(get_class($this)."::updateorCreatePriceFournisseur", LOG_DEBUG);
foreach ($this->lines as $product) { foreach ($this->lines as $product) {
$idProductFourn = $productsupplier->find_min_price_product_fournisseur($product->fk_product, $product->qty); $idProductFourn = $productsupplier->find_min_price_product_fournisseur($product->fk_product, $product->qty);
$res = $productsupplier->fetch($idProductFourn); $res = $productsupplier->fetch($idProductFourn);
if ($productsupplier->id) {
if ($productsupplier->fourn_qty == $product->qty) {
$this->updatePriceFournisseur($productsupplier->product_fourn_price_id, $product, $user);
} else {
$this->createPriceFournisseur($product, $user);
}
} else {
$this->createPriceFournisseur($product, $user);
}
}
}
/**
* Upate ProductFournisseur
*
* @param int $idProductFournPrice id of llx_product_fournisseur_price
* @param int $product contain informations to update
* @param User $user Object user
* @return int <0 if KO, >0 if OK
*/
function updatePriceFournisseur($idProductFournPrice, $product, $user) {
$price=price2num($product->subprice*$product->qty,'MU'); $price=price2num($product->subprice*$product->qty,'MU');
//$qty=price2num($product->qty);
$unitPrice = price2num($product->subprice,'MU'); $unitPrice = price2num($product->subprice,'MU');
//$sql = 'UPDATE '.MAIN_DB_PREFIX.'product_fournisseur_price SET price ='.$price.', quantity ='.$qty.', unitprice ='.$unitPrice.' WHERE rowid = '.$productsupplier->product_fourn_price_id; $sql = 'UPDATE '.MAIN_DB_PREFIX.'product_fournisseur_price SET price ='.$price.', unitprice ='.$unitPrice.' WHERE rowid = '.$idProductFournPrice;
$sql = 'UPDATE '.MAIN_DB_PREFIX.'product_fournisseur_price SET price ='.$price.', unitprice ='.$unitPrice.' WHERE rowid = '.$productsupplier->product_fourn_price_id;
$resql = $this->db->query($sql); $resql = $this->db->query($sql);
if (!resql) { if (!resql) {
@ -1856,6 +1881,41 @@ class AskPriceSupplier extends CommonObject
return -1; return -1;
} }
} }
/**
* Create ProductFournisseur
*
* @param Product $product Object Product
* @param User $user Object user
* @return int <0 if KO, >0 if OK
*/
function createPriceFournisseur($product, $user) {
$price=price2num($product->subprice*$product->qty,'MU');
$qty=price2num($product->qty);
$unitPrice = price2num($product->subprice,'MU');
$now=dol_now();
$values = array(
'`'.$this->db->idate($now).'`',
$product->fk_product,
$this->client->id,
'`'.$this->db->escape($product->ref).'`', //En attente de récupérer la bonne ref fournisseur sur le form
$price,
$qty,
$unitPrice,
$product->tva_tx,
$user->id
);
$sql = 'INSERT INTO '.MAIN_DB_PREFIX.'product_fournisseur_price ';
$sql .= '(datec, fk_product, fk_soc, ref_fourn, price, quantity, unitprice, tva_tx, fk_user) VALUES ('.implode(',', $values).')';
$resql = $this->db->query($sql);
if (!resql) {
$this->error=$this->db->error();
$this->db->rollback();
return -1;
}
} }
/** /**

View File

@ -32,7 +32,7 @@ require_once DOL_DOCUMENT_ROOT .'/core/modules/askpricesupplier/modules_askprice
class mod_askpricesupplier_marbre extends ModeleNumRefAskPriceSupplier class mod_askpricesupplier_marbre extends ModeleNumRefAskPriceSupplier
{ {
var $version='dolibarr'; // 'development', 'experimental', 'dolibarr' var $version='dolibarr'; // 'development', 'experimental', 'dolibarr'
var $prefix='PR'; var $prefix='DF';
var $error=''; var $error='';
var $nom = "Marbre"; var $nom = "Marbre";
@ -101,10 +101,10 @@ class mod_askpricesupplier_marbre extends ModeleNumRefAskPriceSupplier
* Return next value * Return next value
* *
* @param Societe $objsoc Object third party * @param Societe $objsoc Object third party
* @param Propal $propal Object commercial proposal * @param Propal $askpricesupplier Object commercial proposal
* @return string Next value * @return string Next value
*/ */
function getNextValue($objsoc,$propal) function getNextValue($objsoc,$askpricesupplier)
{ {
global $db,$conf; global $db,$conf;

View File

@ -25,13 +25,13 @@
* \brief File that contains the numbering module rules Saphir * \brief File that contains the numbering module rules Saphir
*/ */
require_once DOL_DOCUMENT_ROOT .'/core/modules/askpricesupplier/modules_propale.php'; require_once DOL_DOCUMENT_ROOT .'/core/modules/askpricesupplier/modules_askpricesupplier.php';
/** /**
* Class of file that contains the numbering module rules Saphir * Class of file that contains the numbering module rules Saphir
*/ */
class mod_propale_saphir extends ModeleNumRefAskPriceSupplier class mod_askpricesupplier_saphir extends ModeleNumRefAskPriceSupplier
{ {
var $version='dolibarr'; // 'development', 'experimental', 'dolibarr' var $version='dolibarr'; // 'development', 'experimental', 'dolibarr'
var $error = ''; var $error = '';
@ -123,7 +123,7 @@ class mod_propale_saphir extends ModeleNumRefAskPriceSupplier
$date=$askpricesupplier->datep; $date=$askpricesupplier->datep;
$customercode=$objsoc->code_client; $customercode=$objsoc->code_client;
$numFinal=get_next_value($db,$mask,'propal','ref','',$customercode,$date); $numFinal=get_next_value($db,$mask,'askpricesupplier','ref','',$customercode,$date);
return $numFinal; return $numFinal;
} }

View File

@ -282,19 +282,5 @@ DROP TABLE llx_askpricesupplier_extrafields;
DROP TABLE llx_askpricesupplierdet_extrafields; DROP TABLE llx_askpricesupplierdet_extrafields;
DROP TABLE llx_askpricesupplierdet; DROP TABLE llx_askpricesupplierdet;
DROP TABLE llx_askpricesupplier; DROP TABLE llx_askpricesupplier;
*
* CREATE TABLE IF NOT EXISTS llx_askpricesupplier (
rowid INT AUTO_INCREMENT,
fk_statut INT NOT NULL,
fk_soc INT NOT NULL,
price DOUBLE(24,8),
date_create TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
date_send TIMESTAMP,
PRIMARY KEY pk_rowid (rowid),
CONSTRAINT fk_soc FOREIGN KEY (fk_soc) REFERENCES llx_societe (rowid)
);
*
*
*
* *
*/ */

View File

@ -59,8 +59,8 @@ AskpricesupplierStatusDraft=Brouillon (à valider)
AskpricesupplierStatusValidated=Validée (demande ouverte) AskpricesupplierStatusValidated=Validée (demande ouverte)
AskpricesupplierStatusOpened=Validée (demande ouverte) AskpricesupplierStatusOpened=Validée (demande ouverte)
AskpricesupplierStatusClosed=Fermée AskpricesupplierStatusClosed=Fermée
AskpricesupplierStatusSigned=Signée (à facturer) AskpricesupplierStatusSigned=Acceptée
AskpricesupplierStatusNotSigned=Non signée (fermée) AskpricesupplierStatusNotSigned=Refusée
AskpricesupplierStatusBilled=Facturée AskpricesupplierStatusBilled=Facturée
AskpricesupplierStatusDraftShort=Brouillon AskpricesupplierStatusDraftShort=Brouillon
AskpricesupplierStatusValidatedShort=Validée AskpricesupplierStatusValidatedShort=Validée