Finish module BOM
This commit is contained in:
parent
357c5244f7
commit
53be6492b8
@ -145,6 +145,35 @@ if (empty($reshook))
|
||||
$action = '';
|
||||
}
|
||||
}
|
||||
|
||||
// Add line
|
||||
if ($action == 'updateline' && $user->rights->bom->write)
|
||||
{
|
||||
$langs->load('errors');
|
||||
$error = 0;
|
||||
|
||||
// Set if we used free entry or predefined product
|
||||
$qty=GETPOST('qty', 'int');
|
||||
$efficiency=GETPOST('efficiency', 'int');
|
||||
|
||||
if ($qty == '') {
|
||||
setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('Qty')), null, 'errors');
|
||||
$error++;
|
||||
}
|
||||
|
||||
$bomline = new BOMLine($db);
|
||||
$bomline->fetch($lineid);
|
||||
$bomline->qty = $qty;
|
||||
$bomline->efficiency = $efficiency;
|
||||
|
||||
$result = $bomline->update($user);
|
||||
if ($result <= 0)
|
||||
{
|
||||
setEventMessages($bomline->error, $bomline->errors, 'errors');
|
||||
$action = '';
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -203,6 +203,8 @@ class BOM extends CommonObject
|
||||
*/
|
||||
public function create(User $user, $notrigger = false)
|
||||
{
|
||||
if ($this->efficiency < 0 || $this->efficiency > 1) $this->efficiency = 1;
|
||||
|
||||
return $this->createCommon($user, $notrigger);
|
||||
}
|
||||
|
||||
@ -411,6 +413,8 @@ class BOM extends CommonObject
|
||||
*/
|
||||
public function update(User $user, $notrigger = false)
|
||||
{
|
||||
if ($this->efficiency < 0 || $this->efficiency > 1) $this->efficiency = 1;
|
||||
|
||||
return $this->updateCommon($user, $notrigger);
|
||||
}
|
||||
|
||||
@ -1100,6 +1104,8 @@ class BOMLine extends CommonObject
|
||||
*/
|
||||
public function create(User $user, $notrigger = false)
|
||||
{
|
||||
if ($this->efficiency < 0 || $this->efficiency > 1) $this->efficiency = 1;
|
||||
|
||||
return $this->createCommon($user, $notrigger);
|
||||
}
|
||||
|
||||
@ -1201,6 +1207,8 @@ class BOMLine extends CommonObject
|
||||
*/
|
||||
public function update(User $user, $notrigger = false)
|
||||
{
|
||||
if ($this->efficiency < 0 || $this->efficiency > 1) $this->efficiency = 1;
|
||||
|
||||
return $this->updateCommon($user, $notrigger);
|
||||
}
|
||||
|
||||
@ -1230,8 +1238,6 @@ class BOMLine extends CommonObject
|
||||
public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
|
||||
{
|
||||
global $db, $conf, $langs, $hookmanager;
|
||||
global $dolibarr_main_authentication, $dolibarr_main_demo;
|
||||
global $menumanager;
|
||||
|
||||
if (! empty($conf->dol_no_mouse_hover)) $notooltip=1; // Force disable tooltips
|
||||
|
||||
|
||||
@ -26,10 +26,7 @@
|
||||
* $object (invoice, order, ...)
|
||||
* $conf
|
||||
* $langs
|
||||
* $dateSelector
|
||||
* $forceall (0 by default, 1 for supplier invoices/orders)
|
||||
* $senderissupplier (0 by default, 1 or 2 for supplier invoices/orders)
|
||||
* $inputalsopricewithtax (0 by default, 1 to also show column with unit price including tax)
|
||||
*/
|
||||
|
||||
// Protection to avoid direct call of template
|
||||
@ -39,20 +36,13 @@ if (empty($object) || ! is_object($object)) {
|
||||
}
|
||||
|
||||
|
||||
if (! isset($dateSelector)) global $dateSelector; // Take global var only if not already defined into function calling (for example formAddObjectLine)
|
||||
global $forceall, $forcetoshowtitlelines, $senderissupplier, $inputalsopricewithtax;
|
||||
global $forceall, $forcetoshowtitlelines;
|
||||
|
||||
if (! isset($dateSelector)) $dateSelector=1; // For backward compatibility
|
||||
elseif (empty($dateSelector)) $dateSelector=0;
|
||||
if (empty($forceall)) $forceall=0;
|
||||
if (empty($senderissupplier)) $senderissupplier=0;
|
||||
if (empty($inputalsopricewithtax)) $inputalsopricewithtax=0;
|
||||
|
||||
|
||||
// Define colspan for the button 'Add'
|
||||
$colspan = 3; // Columns: total ht + col edit + col delete
|
||||
if (!empty($conf->multicurrency->enabled) && $this->multicurrency_code != $conf->currency) $colspan++;//Add column for Total (currency) if required
|
||||
if (in_array($object->element, array('propal','commande','order','facture','facturerec','invoice','supplier_proposal','order_supplier','invoice_supplier'))) $colspan++; // With this, there is a column move button
|
||||
//print $object->element;
|
||||
|
||||
// Lines for extrafield
|
||||
@ -135,11 +125,6 @@ if ($nolinesbefore) {
|
||||
print $form->selectUnits($line->fk_unit, "units");
|
||||
print '</td>';
|
||||
}
|
||||
$remise_percent = $buyer->remise_percent;
|
||||
if($object->element == 'supplier_proposal' || $object->element == 'order_supplier' || $object->element == 'invoice_supplier')
|
||||
{
|
||||
$remise_percent = $seller->remise_supplier_percent;
|
||||
}
|
||||
|
||||
$coldisplay++;
|
||||
?>
|
||||
|
||||
@ -39,18 +39,16 @@ if (empty($object) || ! is_object($object))
|
||||
}
|
||||
|
||||
|
||||
global $forceall, $senderissupplier, $inputalsopricewithtax;
|
||||
if (empty($dateSelector)) $dateSelector=0;
|
||||
global $forceall;
|
||||
|
||||
if (empty($forceall)) $forceall=0;
|
||||
if (empty($senderissupplier)) $senderissupplier=0;
|
||||
if (empty($inputalsopricewithtax)) $inputalsopricewithtax=0;
|
||||
|
||||
|
||||
// Define colspan for the button 'Add'
|
||||
$colspan = 3; // Col total ht + col edit + col delete
|
||||
if (! empty($inputalsopricewithtax)) $colspan++; // We add 1 if col total ttc
|
||||
if (in_array($object->element, array('propal','supplier_proposal','facture','facturerec','invoice','commande','order','order_supplier','invoice_supplier'))) $colspan++; // With this, there is a column move button
|
||||
if (!empty($conf->multicurrency->enabled) && $this->multicurrency_code != $conf->currency) $colspan+=2;
|
||||
$colspan = 3; // Columns: total ht + col edit + col delete
|
||||
|
||||
// Lines for extrafield
|
||||
$objectline = new BOMLine($this->db);
|
||||
?>
|
||||
|
||||
<!-- BEGIN PHP TEMPLATE objectline_edit.tpl.php -->
|
||||
@ -59,7 +57,9 @@ if (!empty($conf->multicurrency->enabled) && $this->multicurrency_code != $conf-
|
||||
$coldisplay=0;
|
||||
?>
|
||||
<tr class="oddeven tredited">
|
||||
<?php if (! empty($conf->global->MAIN_VIEW_LINE_NUMBER)) { ?>
|
||||
<?php
|
||||
// Adds a line numbering column
|
||||
if (! empty($conf->global->MAIN_VIEW_LINE_NUMBER)) { ?>
|
||||
<td class="linecolnum center"><?php $coldisplay++; ?><?php echo ($i+1); ?></td>
|
||||
<?php }
|
||||
|
||||
@ -74,27 +74,14 @@ $coldisplay=0;
|
||||
<input type="hidden" id="special_code" name="special_code" value="<?php echo $line->special_code; ?>">
|
||||
<input type="hidden" id="fk_parent_line" name="fk_parent_line" value="<?php echo $line->fk_parent_line; ?>">
|
||||
|
||||
<?php if ($line->fk_product > 0) { ?>
|
||||
|
||||
<?php
|
||||
if ($line->fk_parent_line > 0) echo img_picto('', 'rightarrow');
|
||||
?>
|
||||
<a href="<?php echo DOL_URL_ROOT.'/product/card.php?id='.$line->fk_product; ?>">
|
||||
<?php
|
||||
if ($line->product_type==1) echo img_object($langs->trans('ShowService'), 'service');
|
||||
else print img_object($langs->trans('ShowProduct'), 'product');
|
||||
echo ' '.$line->ref;
|
||||
?>
|
||||
</a>
|
||||
<?php
|
||||
echo ' - '.nl2br($line->product_label);
|
||||
?>
|
||||
|
||||
<br><br>
|
||||
|
||||
<?php } ?>
|
||||
|
||||
<?php
|
||||
// Predefined product/service
|
||||
if ($line->fk_product > 0) {
|
||||
$tmpproduct = new Product($object->db);
|
||||
$tmpproduct->fetch($line->fk_product);
|
||||
print $tmpproduct->getNomUrl(1);
|
||||
}
|
||||
|
||||
if (is_object($hookmanager))
|
||||
{
|
||||
$fk_parent_line = (GETPOST('fk_parent_line') ? GETPOST('fk_parent_line') : $line->fk_parent_line);
|
||||
@ -106,220 +93,53 @@ $coldisplay=0;
|
||||
</td>
|
||||
|
||||
<?php
|
||||
if ($object->element == 'supplier_proposal' || $object->element == 'order_supplier' || $object->element == 'invoice_supplier') // We must have same test in printObjectLines
|
||||
/*if ($object->element == 'supplier_proposal' || $object->element == 'order_supplier' || $object->element == 'invoice_supplier') // We must have same test in printObjectLines
|
||||
{
|
||||
$coldisplay++;
|
||||
?>
|
||||
<td class="right"><input id="fourn_ref" name="fourn_ref" class="flat minwidth75" value="<?php echo ($line->ref_supplier ? $line->ref_supplier : $line->ref_fourn); ?>"></td>
|
||||
<?php
|
||||
}
|
||||
*/
|
||||
|
||||
$coldisplay++;
|
||||
if ($line->fk_prev_id == null) {
|
||||
print '<td class="right">' . $form->load_tva('tva_tx', $line->tva_tx.($line->vat_src_code?(' ('.$line->vat_src_code.')'):''), $seller, $buyer, 0, $line->info_bits, $line->product_type, false, 1) . '</td>';
|
||||
} else {
|
||||
print '<td class="right"><input size="1" type="text" class="flat right" name="tva_tx" value="' . price($line->tva_tx) . '" readonly />%</td>';
|
||||
}
|
||||
|
||||
$coldisplay++;
|
||||
print '<td class="right"><input type="text" class="flat right" size="5" id="price_ht" name="price_ht" value="' . (isset($line->pu_ht)?price($line->pu_ht, 0, '', 0):price($line->subprice, 0, '', 0)) . '"';
|
||||
if ($line->fk_prev_id != null) print ' readonly';
|
||||
print '></td>';
|
||||
|
||||
if (!empty($conf->multicurrency->enabled) && $this->multicurrency_code != $conf->currency) {
|
||||
$coldisplay++;
|
||||
print '<td class="right"><input rel="'.$object->multicurrency_tx.'" type="text" class="flat right" size="5" id="multicurrency_subprice" name="multicurrency_subprice" value="'.price($line->multicurrency_subprice).'" /></td>';
|
||||
}
|
||||
|
||||
if ($inputalsopricewithtax)
|
||||
{
|
||||
$coldisplay++;
|
||||
print '<td class="right"><input type="text" class="flat right" size="5" id="price_ttc" name="price_ttc" value="'.(isset($line->pu_ttc)?price($line->pu_ttc, 0, '', 0):'').'"';
|
||||
if ($line->fk_prev_id != null) print ' readonly';
|
||||
print '></td>';
|
||||
}
|
||||
?>
|
||||
<td class="right"><?php $coldisplay++; ?>
|
||||
<td class="nobottom linecolqty right">
|
||||
<?php if (($line->info_bits & 2) != 2) {
|
||||
// I comment this because it shows info even when not required
|
||||
// for example always visible on invoice but must be visible only if stock module on and stock decrease option is on invoice validation and status is not validated
|
||||
// must also not be output for most entities (proposal, intervention, ...)
|
||||
//if($line->qty > $line->stock) print img_picto($langs->trans("StockTooLow"),"warning", 'style="vertical-align: bottom;"')." ";
|
||||
print '<input size="3" type="text" class="flat right" name="qty" id="qty" value="' . $line->qty . '"';
|
||||
if ($line->fk_prev_id != null ) print ' readonly';
|
||||
print '>';
|
||||
} else { ?>
|
||||
|
||||
<?php } ?>
|
||||
print '<input size="3" type="text" class="flat right" name="qty" id="qty" value="' . $line->qty . '">';
|
||||
}
|
||||
?>
|
||||
</td>
|
||||
|
||||
<?php
|
||||
if($conf->global->PRODUCT_USE_UNITS)
|
||||
{
|
||||
$coldisplay++;
|
||||
print '<td class="left">';
|
||||
print '<td class="nobottom linecoluseunit left">';
|
||||
print $form->selectUnits($line->fk_unit, "units");
|
||||
print '</td>';
|
||||
}
|
||||
|
||||
$coldisplay++;
|
||||
?>
|
||||
<td class="nobottom nowrap linecollost right"><input type="text" size="1" name="efficiency" id="efficiency" class="flat right" value="<?php echo $line->efficiency; ?>"></td>
|
||||
<?php
|
||||
|
||||
<td class="nowrap right"><?php $coldisplay++; ?>
|
||||
<?php if (($line->info_bits & 2) != 2) {
|
||||
print '<input size="1" type="text" class="flat right" name="remise_percent" id="remise_percent" value="' . $line->remise_percent . '"';
|
||||
if ($line->fk_prev_id != null ) print ' readonly';
|
||||
print '>%';
|
||||
} else { ?>
|
||||
|
||||
<?php } ?>
|
||||
</td>
|
||||
|
||||
<!-- colspan for this td because it replace total_ht+3 td for buttons+... -->
|
||||
<td class="center valignmiddle" colspan="<?php echo $colspan; ?>"><?php $coldisplay+=$colspan; ?>
|
||||
$coldisplay+=$colspan;
|
||||
?>
|
||||
<td class="nobottom linecoledit center valignmiddle" colspan="<?php echo $colspan; ?>"><?php $coldisplay+=$colspan; ?>
|
||||
<input type="submit" class="button" id="savelinebutton" name="save" value="<?php echo $langs->trans("Save"); ?>"><br>
|
||||
<input type="submit" class="button" id="cancellinebutton" name="cancel" value="<?php echo $langs->trans("Cancel"); ?>">
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<?php
|
||||
//Line extrafield
|
||||
if (!empty($extrafieldsline))
|
||||
{
|
||||
print $line->showOptionals($extrafieldsline, 'edit', array('style'=>$bc[$var],'colspan'=>$coldisplay), '', '', empty($conf->global->MAIN_EXTRAFIELDS_IN_ONE_TD)?0:1);
|
||||
if (is_object($objectline)) {
|
||||
print $objectline->showOptionals($extrafieldsline, 'edit', array('style'=>$bcnd[$var], 'colspan'=>$coldisplay), '', '', empty($conf->global->MAIN_EXTRAFIELDS_IN_ONE_TD)?0:1);
|
||||
}
|
||||
?>
|
||||
|
||||
<?php if (! empty($conf->service->enabled) && $line->product_type == 1 && $dateSelector) { ?>
|
||||
<tr id="service_duration_area" class="treditedlinefordate">
|
||||
<?php if (! empty($conf->global->MAIN_VIEW_LINE_NUMBER)) { ?>
|
||||
<td class="linecolnum center"></td>
|
||||
<?php } ?>
|
||||
<td colspan="<?php echo $coldisplay-(empty($conf->global->MAIN_VIEW_LINE_NUMBER)?0:1) ?>"><?php echo $langs->trans('ServiceLimitedDuration').' '.$langs->trans('From').' '; ?>
|
||||
<?php
|
||||
$hourmin=(isset($conf->global->MAIN_USE_HOURMIN_IN_DATE_RANGE)?$conf->global->MAIN_USE_HOURMIN_IN_DATE_RANGE:'');
|
||||
print $form->selectDate($line->date_start, 'date_start', $hourmin, $hourmin, $line->date_start?0:1, "updateline", 1, 0);
|
||||
print ' '.$langs->trans('to').' ';
|
||||
print $form->selectDate($line->date_end, 'date_end', $hourmin, $hourmin, $line->date_end?0:1, "updateline", 1, 0);
|
||||
print '<script type="text/javascript">';
|
||||
if (!$line->date_start) {
|
||||
if (isset($conf->global->MAIN_DEFAULT_DATE_START_HOUR)) {
|
||||
print 'jQuery("#date_starthour").val("'.$conf->global->MAIN_DEFAULT_DATE_START_HOUR.'");';
|
||||
}
|
||||
if (isset($conf->global->MAIN_DEFAULT_DATE_START_MIN)) {
|
||||
print 'jQuery("#date_startmin").val("'.$conf->global->MAIN_DEFAULT_DATE_START_MIN.'");';
|
||||
}
|
||||
}
|
||||
if (!$line->date_end) {
|
||||
if (isset($conf->global->MAIN_DEFAULT_DATE_END_HOUR)) {
|
||||
print 'jQuery("#date_endhour").val("'.$conf->global->MAIN_DEFAULT_DATE_END_HOUR.'");';
|
||||
}
|
||||
if (isset($conf->global->MAIN_DEFAULT_DATE_END_MIN)) {
|
||||
print 'jQuery("#date_endmin").val("'.$conf->global->MAIN_DEFAULT_DATE_END_MIN.'");';
|
||||
}
|
||||
}
|
||||
print '</script>'
|
||||
?>
|
||||
</td>
|
||||
</tr>
|
||||
<?php }
|
||||
?>
|
||||
|
||||
|
||||
<script type="text/javascript">
|
||||
|
||||
jQuery(document).ready(function()
|
||||
{
|
||||
jQuery("#price_ht").keyup(function(event) {
|
||||
// console.log(event.which); // discard event tag and arrows
|
||||
if (event.which != 9 && (event.which < 37 ||event.which > 40) && jQuery("#price_ht").val() != '') {
|
||||
jQuery("#price_ttc").val('');
|
||||
jQuery("#multicurrency_subprice").val('');
|
||||
}
|
||||
});
|
||||
jQuery("#price_ttc").keyup(function(event) {
|
||||
// console.log(event.which); // discard event tag and arrows
|
||||
if (event.which != 9 && (event.which < 37 || event.which > 40) && jQuery("#price_ttc").val() != '') {
|
||||
jQuery("#price_ht").val('');
|
||||
jQuery("#multicurrency_subprice").val('');
|
||||
}
|
||||
});
|
||||
jQuery("#multicurrency_subprice").keyup(function(event) {
|
||||
// console.log(event.which); // discard event tag and arrows
|
||||
if (event.which != 9 && (event.which < 37 || event.which > 40) && jQuery("#price_ttc").val() != '') {
|
||||
jQuery("#price_ht").val('');
|
||||
jQuery("#price_ttc").val('');
|
||||
}
|
||||
});
|
||||
|
||||
<?php
|
||||
if (! empty($conf->margin->enabled))
|
||||
{
|
||||
?>
|
||||
/* Add rule to clear margin when we change some data, so when we change sell or buy price, margin will be recalculated after submitting form */
|
||||
jQuery("#tva_tx").click(function() { /* somtimes field is a text, sometimes a combo */
|
||||
jQuery("input[name='np_marginRate']:first").val('');
|
||||
jQuery("input[name='np_markRate']:first").val('');
|
||||
});
|
||||
jQuery("#tva_tx").keyup(function() { /* somtimes field is a text, sometimes a combo */
|
||||
jQuery("input[name='np_marginRate']:first").val('');
|
||||
jQuery("input[name='np_markRate']:first").val('');
|
||||
});
|
||||
jQuery("#price_ht").keyup(function() {
|
||||
jQuery("input[name='np_marginRate']:first").val('');
|
||||
jQuery("input[name='np_markRate']:first").val('');
|
||||
});
|
||||
jQuery("#qty").keyup(function() {
|
||||
jQuery("input[name='np_marginRate']:first").val('');
|
||||
jQuery("input[name='np_markRate']:first").val('');
|
||||
});
|
||||
jQuery("#remise_percent").keyup(function() {
|
||||
jQuery("input[name='np_marginRate']:first").val('');
|
||||
jQuery("input[name='np_markRate']:first").val('');
|
||||
});
|
||||
jQuery("#buying_price").keyup(function() {
|
||||
jQuery("input[name='np_marginRate']:first").val('');
|
||||
jQuery("input[name='np_markRate']:first").val('');
|
||||
});
|
||||
|
||||
/* Init field buying_price and fournprice */
|
||||
$.post('<?php echo DOL_URL_ROOT; ?>/fourn/ajax/getSupplierPrices.php', {'idprod': <?php echo $line->fk_product?$line->fk_product:0; ?>}, function(data) {
|
||||
if (data && data.length > 0) {
|
||||
var options = '';
|
||||
var trouve=false;
|
||||
$(data).each(function() {
|
||||
options += '<option value="'+this.id+'" price="'+this.price+'"';
|
||||
<?php if ($line->fk_fournprice > 0) { ?>
|
||||
if (this.id == <?php echo $line->fk_fournprice; ?>) {
|
||||
options += ' selected';
|
||||
$("#buying_price").val(this.price);
|
||||
trouve = true;
|
||||
}
|
||||
<?php } ?>
|
||||
options += '>'+this.label+'</option>';
|
||||
});
|
||||
options += '<option value=null'+(trouve?'':' selected')+'><?php echo $langs->trans("InputPrice"); ?></option>';
|
||||
$("#fournprice").html(options);
|
||||
if (trouve) {
|
||||
$("#buying_price").hide();
|
||||
$("#fournprice").show();
|
||||
} else {
|
||||
$("#buying_price").show();
|
||||
}
|
||||
$("#fournprice").change(function() {
|
||||
var selval = $(this).find('option:selected').attr("price");
|
||||
if (selval)
|
||||
$("#buying_price").val(selval).hide();
|
||||
else
|
||||
$('#buying_price').show();
|
||||
});
|
||||
} else {
|
||||
$("#fournprice").hide();
|
||||
$('#buying_price').show();
|
||||
}
|
||||
}, 'json');
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
});
|
||||
|
||||
</script>
|
||||
<!-- END PHP TEMPLATE objectline_edit.tpl.php -->
|
||||
|
||||
Loading…
Reference in New Issue
Block a user