Work on supplier order and customer extrafields

Use templates to show/edit supplier order and invoice lines
This commit is contained in:
Laurent Destailleur 2015-02-27 18:05:12 +01:00
parent a87c867c28
commit 5d1545ad1f
10 changed files with 123 additions and 56 deletions

View File

@ -786,9 +786,10 @@ if (empty($reshook))
}
/*
* Mise a jour d'une ligne dans la commande
*/
else if ($action == 'updateligne' && $user->rights->commande->creer && GETPOST('save') == $langs->trans('Save')) {
* Update a line
*/
else if ($action == 'updateline' && $user->rights->commande->creer && GETPOST('save') == $langs->trans('Save'))
{
// Clean parameters
$date_start='';
$date_end='';
@ -891,7 +892,7 @@ if (empty($reshook))
}
}
else if ($action == 'updateligne' && $user->rights->commande->creer && GETPOST('cancel') == $langs->trans('Cancel')) {
else if ($action == 'updateline' && $user->rights->commande->creer && GETPOST('cancel') == $langs->trans('Cancel')) {
header('Location: ' . $_SERVER['PHP_SELF'] . '?id=' . $object->id); // Pour reaffichage de la fiche en cours d'edition
exit();
}
@ -2101,7 +2102,7 @@ if ($action == 'create' && $user->rights->commande->creer)
print ' <form name="addproduct" id="addproduct" action="' . $_SERVER["PHP_SELF"] . '?id=' . $object->id . (($action != 'editline') ? '#add' : '#line_' . GETPOST('lineid')) . '" method="POST">
<input type="hidden" name="token" value="' . $_SESSION ['newtoken'] . '">
<input type="hidden" name="action" value="' . (($action != 'editline') ? 'addline' : 'updateligne') . '">
<input type="hidden" name="action" value="' . (($action != 'editline') ? 'addline' : 'updateline') . '">
<input type="hidden" name="mode" value="">
<input type="hidden" name="id" value="' . $object->id . '">
';

View File

@ -2137,7 +2137,7 @@ abstract class CommonObject
$fieldstatus="fk_statut";
if ($elementTable == 'user') $fieldstatus="statut";
if ($elementTable == 'expensereport') $fieldstatus="fk_c_expensereport_statuts";
$sql = "UPDATE ".MAIN_DB_PREFIX.$elementTable;
$sql.= " SET ".$fieldstatus." = ".$status;
// If status = 1 = validated, update also fk_user_valid
@ -2572,7 +2572,12 @@ abstract class CommonObject
*/
function printObjectLines($action, $seller, $buyer, $selected=0, $dateSelector=0)
{
global $conf, $hookmanager, $inputalsopricewithtax, $langs, $user;
global $conf, $hookmanager, $inputalsopricewithtax, $usermargins, $langs, $user;
# Define usemargins
$usemargins=0;
if (! empty($conf->margin->enabled) && ! empty($this->element) && in_array($this->element,array('facture','propal','commande'))) $usemargins=1;
print '<tr class="liste_titre nodrag nodrop">';
@ -2599,7 +2604,7 @@ abstract class CommonObject
print '<td align="right" width="50"><label for="progress">' . $langs->trans('Progress') . '</label></td>';
}
if (! empty($conf->margin->enabled) && empty($user->societe_id))
if ($usermargins && ! empty($conf->margin->enabled) && empty($user->societe_id))
{
if ($conf->global->MARGIN_TYPE == "1")
print '<td align="right" class="margininfos" width="80">'.$langs->trans('BuyingPrice').'</td>';

View File

@ -208,6 +208,8 @@ class DoliDBPgsql extends DoliDB
$line=preg_replace('/tinytext/i','text',$line);
$line=preg_replace('/mediumtext/i','text',$line);
$line=preg_replace('/text\([0-9]+\)/i','text',$line);
// change not null datetime field to null valid ones
// (to support remapping of "zero time" to null
$line=preg_replace('/datetime not null/i','datetime',$line);

View File

@ -263,7 +263,8 @@ else {
</td>
<?php
// Lines for extrafield
if (!empty($extrafieldsline)) {
if (!empty($extrafieldsline))
{
if ($this->table_element_line=='commandedet') {
$newline = new OrderLine($this->db);
}
@ -276,6 +277,12 @@ else {
elseif ($this->table_element_line=='contratdet') {
$newline = new ContratLigne($this->db);
}
elseif ($this->table_element_line=='commande_fournisseurdet') {
$newline = new CommandeFournisseurLigne($this->db);
}
elseif ($this->table_element_line=='facture_fourn_det') {
$newline = new FactureFournisseurLigne($this->db);
}
if (is_object($newline)) {
print $newline->showOptionals($extrafieldsline, 'edit', array('style'=>$bcnd[$var], 'colspan'=>$coldisplay+8));
}

View File

@ -199,7 +199,8 @@ $coldisplay=-1; // We remove first td
<?php
//Line extrafield
if (!empty($extrafieldsline)) {
if (!empty($extrafieldsline))
{
print $line->showOptionals($extrafieldsline,'edit',array('style'=>$bc[$var],'colspan'=>$coldisplay));
}
?>

View File

@ -27,18 +27,17 @@
* $forceall (0 by default, 1 for supplier invoices/orders)
* $senderissupplier (0 by default, 1 for supplier invoices/orders)
* $inputalsopricewithtax (0 by default, 1 to also show column with unit price including tax)
* $usemargins (0 to disable all margins columns, 1 to show according to margin setup)
*
* $type, $text, $description, $line
*/
$usemargins=0;
if (! empty($conf->margin->enabled) && ! empty($object->element) && in_array($object->element,array('facture','propal','commande'))) $usemargins=1;
global $forceall, $senderissupplier, $inputalsopricewithtax;
global $forceall, $senderissupplier, $inputalsopricewithtax, $usemargins;
if (empty($dateSelector)) $dateSelector=0;
if (empty($forceall)) $forceall=0;
if (empty($senderissupplier)) $senderissupplier=0;
if (empty($inputalsopricewithtax)) $inputalsopricewithtax=0;
if (empty($usemargins)) $usemargins=0;
?>
<?php $coldisplay=0; ?>
@ -83,7 +82,8 @@ if (empty($inputalsopricewithtax)) $inputalsopricewithtax=0;
}
else
{
if ($line->fk_product > 0) {
if ($line->fk_product > 0)
{
echo $form->textwithtooltip($text,$description,3,'','',$i,0,(!empty($line->fk_parent_line)?img_picto('', 'rightarrow'):''));
@ -96,7 +96,9 @@ if (empty($inputalsopricewithtax)) $inputalsopricewithtax=0;
print (! empty($line->description) && $line->description!=$line->product_label)?'<br>'.dol_htmlentitiesbr($line->description):'';
}
} else {
}
else
{
if ($type==1) $text = img_object($langs->trans('Service'),'service');
else $text = img_object($langs->trans('Product'),'product');
@ -145,17 +147,19 @@ if (empty($inputalsopricewithtax)) $inputalsopricewithtax=0;
print '<td align="right" nowrap="nowrap">' . $line->situation_percent . '%</td>';
}
if (! empty($conf->margin->enabled) && empty($user->societe_id)) {
$rounding = min($conf->global->MAIN_MAX_DECIMALS_UNIT,$conf->global->MAIN_MAX_DECIMALS_TOT);
?>
if ($usermargins && ! empty($conf->margin->enabled) && empty($user->societe_id))
{
$rounding = min($conf->global->MAIN_MAX_DECIMALS_UNIT,$conf->global->MAIN_MAX_DECIMALS_TOT);
?>
<td align="right" class="nowrap margininfos"><?php $coldisplay++; ?><?php echo price($line->pa_ht); ?></td>
<?php if (! empty($conf->global->DISPLAY_MARGIN_RATES) && $user->rights->margins->liretous) {?>
<?php if (! empty($conf->global->DISPLAY_MARGIN_RATES) && $user->rights->margins->liretous) { ?>
<td align="right" class="nowrap margininfos"><?php $coldisplay++; ?><?php echo (($line->pa_ht == 0)?'n/a':price($line->marge_tx, null, null, null, null, $rounding).'%'); ?></td>
<?php
}
if (! empty($conf->global->DISPLAY_MARK_RATES) && $user->rights->margins->liretous) {?>
<?php }
if (! empty($conf->global->DISPLAY_MARK_RATES) && $user->rights->margins->liretous) {?>
<td align="right" class="nowrap margininfos"><?php $coldisplay++; ?><?php echo price($line->marque_tx, null, null, null, null, $rounding).'%'; ?></td>
<?php } } ?>
<?php }
}
?>
<?php if ($line->special_code == 3) { ?>
<td align="right" class="nowrap"><?php $coldisplay++; ?><?php echo $langs->trans('Option'); ?></td>

View File

@ -1814,3 +1814,15 @@ class FactureFournisseur extends CommonInvoice
}
}
/**
* Class to manage line invoices
*/
class FactureFournisseurLigne extends CommonInvoiceLine
{
}

View File

@ -63,6 +63,8 @@ $confirm = GETPOST('confirm','alpha');
$comclientid = GETPOST('comid','int');
$socid = GETPOST('socid','int');
$projectid = GETPOST('projectid','int');
$cancel = GETPOST('cancel','alpha');
$lineid = GETPOST('lineid', 'int');
//PDF
$hidedetails = (GETPOST('hidedetails','int') ? GETPOST('hidedetails','int') : (! empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DETAILS) ? 1 : 0));
@ -113,6 +115,8 @@ $permissionnote=$user->rights->fournisseur->commande->creer; // Used by the incl
* Actions
*/
if ($cancel) $action='';
$parameters=array('socid'=>$socid);
$reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
@ -402,7 +406,7 @@ if ($action == 'addline' && $user->rights->fournisseur->commande->creer)
/*
* Mise a jour d'une ligne dans la commande
*/
if ($action == 'update_line' && $user->rights->fournisseur->commande->creer && ! GETPOST('cancel'))
if ($action == 'updateline' && $user->rights->fournisseur->commande->creer && ! GETPOST('cancel'))
{
if ($_POST["elrowid"])
{
@ -1693,23 +1697,32 @@ elseif (! empty($object->id))
/*
* Lines
*/
//$result = $object->getLinesArray();
print ' <form name="addproduct" id="addproduct" action="'.$_SERVER["PHP_SELF"].'?etat=1&id='.$object->id.(($action != 'edit_line')?'#add':'#line_'.GETPOST('lineid')).'" method="POST">
print ' <form name="addproduct" id="addproduct" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.(($action != 'editline')?'#add':'#line_'.GETPOST('lineid')).'" method="POST">
<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">
<input type="hidden" name="action" value="'.(($action != 'edit_line')?'addline':'update_line').'">
<input type="hidden" name="action" value="' . (($action != 'editline') ? 'addline' : 'updateline') . '">
<input type="hidden" name="mode" value="">
<input type="hidden" name="id" value="'.$object->id.'">
<input type="hidden" name="facid" value="'.$object->id.'">
<input type="hidden" name="socid" value="'.$societe->id.'">
';
if (! empty($conf->use_javascript_ajax) && $object->statut == 0) {
include DOL_DOCUMENT_ROOT . '/core/tpl/ajaxrow.tpl.php';
}
print '<table id="tablelines" class="noborder noshadow" width="100%">';
$num = count($object->lines);
$i = 0; $total = 0;
// Show object lines
$inputalsopricewithtax=1;
if (! empty($object->lines))
$ret = $object->printObjectLines($action, $soc, $mysoc, $lineid, 1);
$num = count($object->lines);
/*
$i = 0; $total = 0;
if ($num)
{
print '<tr class="liste_titre">';
@ -1746,7 +1759,7 @@ elseif (! empty($object->id))
}
// Edit line
if ($action != 'edit_line' || $_GET['rowid'] != $line->id)
if ($action != 'editline' || $_GET['rowid'] != $line->id)
{
print '<tr id="row-'.$line->id.'" '.$bc[$var].'>';
@ -1808,7 +1821,7 @@ elseif (! empty($object->id))
if ($object->statut == 0 && $user->rights->fournisseur->commande->creer)
{
print '<td align="center" width="16"><a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=edit_line&amp;rowid='.$line->id.'#'.$line->id.'">';
print '<td align="center" width="16"><a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=editline&amp;rowid='.$line->id.'#'.$line->id.'">';
print img_edit();
print '</a></td>';
@ -1825,7 +1838,7 @@ elseif (! empty($object->id))
}
// Edit line
if ($action == 'edit_line' && $user->rights->fournisseur->commande->creer && ($_GET["rowid"] == $line->id))
if ($action == 'editline' && $user->rights->fournisseur->commande->creer && ($_GET["rowid"] == $line->id))
{
print "\n";
print '<tr '.$bc[$var].'>';
@ -1885,9 +1898,9 @@ elseif (! empty($object->id))
}
$i++;
}
*/
// Form to add new line
if ($object->statut == 0 && $user->rights->fournisseur->commande->creer && $action != 'edit_line')
if ($object->statut == 0 && $user->rights->fournisseur->commande->creer && $action != 'editline')
{
// Add free products/services form
global $forceall, $senderissupplier, $dateSelector;
@ -2235,7 +2248,7 @@ elseif (! empty($object->id))
// modified by hook
if (empty($reshook))
{
if ($user->societe_id == 0 && $action != 'edit_line' && $action != 'delete')
if ($user->societe_id == 0 && $action != 'editline' && $action != 'delete')
{
print '<div class="tabsAction">';

View File

@ -57,6 +57,8 @@ $id = (GETPOST('facid','int') ? GETPOST('facid','int') : GETPOST('id','int'));
$action = GETPOST("action");
$confirm = GETPOST("confirm");
$ref = GETPOST('ref','alpha');
$cancel = GETPOST('cancel','alpha');
$lineid = GETPOST('lineid', 'int');
//PDF
$hidedetails = (GETPOST('hidedetails','int') ? GETPOST('hidedetails','int') : (! empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DETAILS) ? 1 : 0));
@ -90,6 +92,8 @@ $permissionnote=$user->rights->fournisseur->facture->creer; // Used by the inclu
* Actions
*/
if ($cancel) $action='';
$parameters=array('socid'=>$socid);
$reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
@ -503,12 +507,11 @@ elseif ($action == 'add' && $user->rights->fournisseur->facture->creer)
}
// Edit line
elseif ($action == 'update_line' && $user->rights->fournisseur->facture->creer)
elseif ($action == 'updateline' && $user->rights->fournisseur->facture->creer)
{
// TODO Missing transaction
if (GETPOST('etat') == '1' && ! GETPOST('cancel')) // si on valide la modification
{
$object->fetch($id);
$db->begin();
$object->fetch($id);
$object->fetch_thirdparty();
if ($_POST['puht'])
@ -547,12 +550,13 @@ elseif ($action == 'update_line' && $user->rights->fournisseur->facture->creer)
if ($result >= 0)
{
unset($_POST['label']);
$db->commit();
}
else
{
$db->rollback();
setEventMessage($object->error,'errors');
}
}
}
elseif ($action == 'addline' && $user->rights->fournisseur->facture->creer)
@ -1954,11 +1958,10 @@ else
$cols = 4;
include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_view.tpl.php';
print '</table>';
print '</table><br>';
if (! empty($conf->global->MAIN_DISABLE_CONTACTS_TAB))
{
print '<br>';
$blocname = 'contacts';
$title = $langs->trans('ContactsAddresses');
include DOL_DOCUMENT_ROOT.'/core/tpl/bloc_showhide.tpl.php';
@ -1976,23 +1979,31 @@ else
/*
* Lines
*/
//$result = $object->getLinesArray();
print ' <form name="addproduct" id="addproduct" action="'.$_SERVER["PHP_SELF"].'?etat=1&id='.$object->id.(($action != 'edit_line')?'#add':'#line_'.GETPOST('lineid')).'" method="POST">
print ' <form name="addproduct" id="addproduct" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.(($action != 'editline')?'#add':'#line_'.GETPOST('lineid')).'" method="POST">
<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">
<input type="hidden" name="action" value="'.(($action != 'edit_line')?'addline':'update_line').'">
<input type="hidden" name="action" value="' . (($action != 'editline') ? 'addline' : 'updateline') . '">
<input type="hidden" name="mode" value="">
<input type="hidden" name="id" value="'.$object->id.'">
<input type="hidden" name="facid" value="'.$object->id.'">
<input type="hidden" name="socid" value="'.$societe->id.'">
';
if (! empty($conf->use_javascript_ajax) && $object->statut == 0) {
include DOL_DOCUMENT_ROOT . '/core/tpl/ajaxrow.tpl.php';
}
print '<br>';
print '<table id="tablelines" class="noborder noshadow" width="100%">';
$var=1;
$num=count($object->lines);
print '<table id="tablelines" class="noborder noshadow" width="100%">';
// Show object lines
if (! empty($object->lines))
$ret = $object->printObjectLines($action, $soc, $mysoc, $lineid, 1);
$num=count($object->lines);
/*
$var=1;
for ($i = 0; $i < $num; $i++)
{
if ($i == 0)
@ -2029,7 +2040,7 @@ else
$var=!$var;
// Edit line
if ($object->statut == 0 && $action == 'edit_line' && $_GET['etat'] == '0' && $_GET['lineid'] == $object->lines[$i]->rowid)
if ($object->statut == 0 && $action == 'editline' && $_GET['lineid'] == $object->lines[$i]->rowid)
{
print '<tr '.$bc[$var].'>';
@ -2156,7 +2167,7 @@ else
}
print '<td align="center" width="16">';
if ($object->statut == 0) print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=edit_line&amp;etat=0&amp;lineid='.$object->lines[$i]->rowid.'">'.img_edit().'</a>';
if ($object->statut == 0) print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=editline&amp;etat=0&amp;lineid='.$object->lines[$i]->rowid.'">'.img_edit().'</a>';
else print '&nbsp;';
print '</td>';
@ -2172,9 +2183,9 @@ else
}
}
*/
// Form to add new line
if ($object->statut == 0 && $action != 'edit_line')
if ($object->statut == 0 && $action != 'editline')
{
global $forceall, $senderissupplier, $dateSelector, $inputalsopricewithtax;
$forceall=1; $senderissupplier=1; $dateSelector=0; $inputalsopricewithtax=1;
@ -2195,6 +2206,7 @@ else
print '</table>';
print '</form>';
dol_fiche_end();

View File

@ -209,3 +209,13 @@ create table llx_commande_fournisseurdet_extrafields
ALTER TABLE llx_commande_fournisseurdet_extrafields ADD INDEX idx_commande_fournisseurdet_extrafields (fk_object);
create table llx_facture_fourn_det_extrafields
(
rowid integer AUTO_INCREMENT PRIMARY KEY,
tms timestamp,
fk_object integer NOT NULL,
import_key varchar(14) -- import key
) ENGINE=innodb;
ALTER TABLE llx_facture_fourn_det_extrafields ADD INDEX idx_facture_fourn_det_extrafields (fk_object);