Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NEW : Billing Term field database #32129

Open
wants to merge 8 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions htdocs/compta/facture/card-rec.php
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,10 @@
} elseif ($action == 'setmulticurrencyrate' && $usercancreate) {
// Multicurrency rate
$result = $object->setMulticurrencyRate(price2num(GETPOST('multicurrency_tx')), GETPOSTINT('calculation_mode'));
} elseif ($action == 'setruleforlinesdates' && $usercancreate) {
$object->context['actionmsg'] = $langs->trans("FieldXModified", $langs->transnoentitiesnoconv("RuleForLinesDates"));

Check failure on line 433 in htdocs/compta/facture/card-rec.php

View workflow job for this annotation

GitHub Actions / pre-commit / pre-commit

Missing translation; $object->context['actionmsg'] = $langs->trans("FieldXModified", $langs->transnoentitiesnoconv("RuleForLinesDates"));
$ruleForLinesDates = GETPOSTISSET('rule_for_lines_dates') ? GETPOST('rule_for_lines_dates', 'alpha') : 'prepaid';
$object->setValueFrom('rule_for_lines_dates', $ruleForLinesDates);
}

// Delete line
Expand Down Expand Up @@ -1493,6 +1497,24 @@
print "</td>";
print '</tr>';


// Billing Term
print '<tr><td>';
print '<table class="nobordernopadding centpercent"><tr><td>';
print $langs->trans('RuleForLinesDates');

Check failure on line 1504 in htdocs/compta/facture/card-rec.php

View workflow job for this annotation

GitHub Actions / pre-commit / pre-commit

Missing translation; print $langs->trans('RuleForLinesDates');
print '</td>';
if ($action != 'editruleforlinesdates' && $user->hasRight('facture', 'creer')) {
print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editruleforlinesdates&token='.newToken().'&facid='.$object->id.'">'.img_edit($langs->trans('SetRuleForLinesDates'), 1).'</a></td>';

Check failure on line 1507 in htdocs/compta/facture/card-rec.php

View workflow job for this annotation

GitHub Actions / pre-commit / pre-commit

Missing translation; print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editruleforlinesdates&token='.newToken().'&facid='.$object->id.'">'.img_edit($langs->trans('SetRuleForLinesDates'), 1).'</a></td>';
}
print '</tr></table>';
print '</td><td>';
if ($action == 'editruleforlinesdates') {
$form->form_rule_for_lines_dates($_SERVER['PHP_SELF'].'?facid='.$object->id, $object->rule_for_lines_dates, 'rule_for_lines_dates');
} else {
$form->form_rule_for_lines_dates($_SERVER['PHP_SELF'].'?facid='.$object->id, $object->rule_for_lines_dates, 'none');
}
print '</td></tr>';

// Extrafields
include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';

Expand Down
1 change: 1 addition & 0 deletions htdocs/compta/facture/card.php
Original file line number Diff line number Diff line change
Expand Up @@ -1809,6 +1809,7 @@
if (isset($lines[$i]->date_debut_reel)) {
$date_start = $lines[$i]->date_debut_reel;
}

if (isset($lines[$i]->date_start)) {
$date_start = $lines[$i]->date_start;
}
Expand Down
13 changes: 11 additions & 2 deletions htdocs/compta/facture/class/facture-rec.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,11 @@ class FactureRec extends CommonInvoice
*/
public $unit_frequency;

/**
* @var string
*/
public $rule_for_lines_dates;

/**
* @var int
*/
Expand Down Expand Up @@ -259,9 +264,10 @@ class FactureRec extends CommonInvoice
'date_when' => array('type' => 'datetime', 'label' => 'Date when', 'enabled' => 1, 'visible' => -1, 'position' => 130),
'date_last_gen' => array('type' => 'datetime', 'label' => 'Date last gen', 'enabled' => 1, 'visible' => -1, 'position' => 135),
'nb_gen_done' => array('type' => 'integer', 'label' => 'Nb gen done', 'enabled' => 1, 'visible' => -1, 'position' => 140),
'nb_gen_max' => array('type' => 'integer', 'label' => 'Nb gen max', 'enabled' => 1, 'visible' => -1, 'position' => 145),
'nb_gen_max' => array('type' => 'integer', 'label' => 'Nb gen max', 'enabled' => 1, 'visible' => -1, 'position' => 145, ),
'frequency' => array('type' => 'integer', 'label' => 'Frequency', 'enabled' => 1, 'visible' => -1, 'position' => 150),
'unit_frequency' => array('type' => 'varchar(2)', 'label' => 'UnitFrequency', 'enabled' => 1, 'visible' => -1, 'position' => 152),
'rule_for_lines_dates' => array('type' => 'varchar(255)', 'label' => 'RuleForLinesDates', 'enabled' => 1, 'visible' => 1, 'position' => 153, 'arrayofkeyval' => array('prepaid' => "Prepaid", 'postpaid' => "Postpaid"), 'default' => 'prepaid'),
'usenewprice' => array('type' => 'integer', 'label' => 'UseNewPrice', 'enabled' => 1, 'visible' => 0, 'position' => 155),
'revenuestamp' => array('type' => 'double(24,8)', 'label' => 'RevenueStamp', 'enabled' => 1, 'visible' => -1, 'position' => 160, 'isameasure' => 1),
'auto_validate' => array('type' => 'integer', 'label' => 'Auto validate', 'enabled' => 1, 'visible' => -1, 'position' => 165),
Expand Down Expand Up @@ -358,6 +364,7 @@ public function create($user, $facid, $notrigger = 0, $onlylines = array())
$sql .= ", usenewprice";
$sql .= ", frequency";
$sql .= ", unit_frequency";
$sql .= ", rule_for_lines_dates";
$sql .= ", date_when";
$sql .= ", date_last_gen";
$sql .= ", nb_gen_done";
Expand Down Expand Up @@ -388,6 +395,7 @@ public function create($user, $facid, $notrigger = 0, $onlylines = array())
$sql .= ", ".((int) $this->usenewprice);
$sql .= ", ".((int) $this->frequency);
$sql .= ", '".$this->db->escape($this->unit_frequency)."'";
$sql .= ", '".($this->rule_for_lines_dates);
$sql .= ", ".(!empty($this->date_when) ? "'".$this->db->idate($this->date_when)."'" : 'NULL');
$sql .= ", ".(!empty($this->date_last_gen) ? "'".$this->db->idate($this->date_last_gen)."'" : 'NULL');
$sql .= ", ".((int) $this->nb_gen_done);
Expand Down Expand Up @@ -626,7 +634,7 @@ public function fetch($rowid, $ref = '', $ref_ext = '', $noextrafields = 0, $nol
$sql .= ', f.modelpdf as model_pdf';
$sql .= ', f.fk_mode_reglement, f.fk_cond_reglement, f.fk_projet as fk_project';
$sql .= ', f.fk_account, f.fk_societe_rib';
$sql .= ', f.frequency, f.unit_frequency, f.date_when, f.date_last_gen, f.nb_gen_done, f.nb_gen_max, f.usenewprice, f.auto_validate';
$sql .= ', f.frequency, f.unit_frequency, f.rule_for_lines_dates, f.date_when, f.date_last_gen, f.nb_gen_done, f.nb_gen_max, f.usenewprice, f.auto_validate';
$sql .= ', f.generate_pdf';
$sql .= ", f.fk_multicurrency, f.multicurrency_code, f.multicurrency_tx, f.multicurrency_total_ht, f.multicurrency_total_tva, f.multicurrency_total_ttc";
$sql .= ', p.code as mode_reglement_code, p.libelle as mode_reglement_libelle';
Expand Down Expand Up @@ -685,6 +693,7 @@ public function fetch($rowid, $ref = '', $ref_ext = '', $noextrafields = 0, $nol
//$this->special_code = $obj->special_code;
$this->frequency = $obj->frequency;
$this->unit_frequency = $obj->unit_frequency;
$this->rule_for_lines_dates = $obj->rule_for_lines_dates;
$this->date_when = $this->db->jdate($obj->date_when);
$this->date_last_gen = $this->db->jdate($obj->date_last_gen);
$this->nb_gen_done = $obj->nb_gen_done;
Expand Down
17 changes: 15 additions & 2 deletions htdocs/compta/facture/class/facture.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -562,12 +562,25 @@ public function create(User $user, $notrigger = 0, $forceduedate = 0)
}

// Define some dates

$originaldatewhen = $_facrec->date_when;
$nextdatewhen = null;
$previousdaynextdatewhen = null;

if ($originaldatewhen) {
$nextdatewhen = dol_time_plus_duree($originaldatewhen, $_facrec->frequency, $_facrec->unit_frequency);
$previousdaynextdatewhen = dol_time_plus_duree($nextdatewhen, -1, 'd');
if ($_facrec->rule_for_lines_dates == 'prepaid') {
$nextdatewhen = dol_time_plus_duree($originaldatewhen, $_facrec->frequency, $_facrec->unit_frequency);
}

if ($_facrec->rule_for_lines_dates == 'postpaid') {
$previousdaynextdatewhen = dol_time_plus_duree($originaldatewhen, -1, 'd');
} else {
$previousdaynextdatewhen = dol_time_plus_duree($nextdatewhen, -1, 'd');
}

$originaldatewhen = $_facrec->rule_for_lines_dates == 'postpaid'
? dol_time_plus_duree($originaldatewhen, -$_facrec->frequency, $_facrec->unit_frequency)
: $originaldatewhen;
}

if (!empty($_facrec->frequency)) { // Invoice are created on same thirdparty than template when there is a recurrence, but not necessarily when there is no recurrence.
Expand Down
84 changes: 84 additions & 0 deletions htdocs/core/class/html.form.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
public $cache_types_fees = array();
public $cache_vatrates = array();
public $cache_invoice_subtype = array();
public $cache_rule_for_lines_dates = array();


/**
Expand Down Expand Up @@ -4296,6 +4297,20 @@
}
}

public function load_cache_rule_for_lines_dates()

Check failure on line 4300 in htdocs/core/class/html.form.class.php

View workflow job for this annotation

GitHub Actions / pre-commit / pre-commit

Missing doc comment for function load_cache_rule_for_lines_dates()

Check failure on line 4300 in htdocs/core/class/html.form.class.php

View workflow job for this annotation

GitHub Actions / pre-commit / pre-commit

Public method name "Form::load_cache_rule_for_lines_dates" is not in camel caps format
{
$factureRec = new FactureRec($this->db);

$this->cache_rule_for_lines_dates = $factureRec->fields['rule_for_lines_dates']['arrayofkeyval'];

if (empty($this->cache_rule_for_lines_dates)) {
return -1;
}

return 1;

}

Check failure on line 4312 in htdocs/core/class/html.form.class.php

View workflow job for this annotation

GitHub Actions / pre-commit / pre-commit

Function closing brace must go on the next line following the body; found 1 blank lines before brace

// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps

/**
Expand Down Expand Up @@ -4652,6 +4667,35 @@
return $out;
}

public function getSelectRuleForLinesDates($selected = '', $htmlname = 'rule_for_lines_dates', $addempty = 0)

Check failure on line 4670 in htdocs/core/class/html.form.class.php

View workflow job for this annotation

GitHub Actions / pre-commit / pre-commit

Missing doc comment for function getSelectRuleForLinesDates()
{
$out = '';

$this->load_cache_rule_for_lines_dates();

$out .= '<select id="' . $htmlname . '" class="flat selectbillingterm" name="' . $htmlname . '">';
if ($addempty) {
$out .= '<option value="-1">&nbsp;</option>';
}


foreach ($this->cache_rule_for_lines_dates as $rule_for_lines_dates_key => $rule_for_lines_dates_name) {
if ($selected == $rule_for_lines_dates_key) {
$out .= '<option value="' . $rule_for_lines_dates_key . '" selected>';
} else {
$out .= '<option value="' . $rule_for_lines_dates_key . '">';
}

$out .= $rule_for_lines_dates_name;
$out .= '</option>';
}
$out .= '</select>';

$out .= ajax_combobox($htmlname);

return $out;
}


// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps

Expand Down Expand Up @@ -6127,6 +6171,46 @@

// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps

/**

Check failure on line 6174 in htdocs/core/class/html.form.class.php

View workflow job for this annotation

GitHub Actions / pre-commit / pre-commit

Doc comment for parameter "$nooutput" missing
* @param $page

Check failure on line 6175 in htdocs/core/class/html.form.class.php

View workflow job for this annotation

GitHub Actions / pre-commit / pre-commit

Missing parameter comment
* @param $selected

Check failure on line 6176 in htdocs/core/class/html.form.class.php

View workflow job for this annotation

GitHub Actions / pre-commit / pre-commit

Missing parameter comment
* @param $htmlname
* @param $addempty
* @return string
*/
public function form_rule_for_lines_dates($page, $selected = '', $htmlname = 'rule_for_lines_dates', $addempty = 0, $nooutput = 0): string
{
global $langs;

$out = '';

if ($htmlname != 'none') {
$out .= '<form method="POST" action="' . $page . '">';
$out .= '<input type="hidden" name="action" value="setruleforlinesdates">';
$out .= '<input type="hidden" name="token" value="' . newToken() . '">';
$out .= $this->getSelectRuleForLinesDates($selected, $htmlname, $addempty);
$out .= '<input type="submit" class="button valignmiddle smallpaddingimp" value="' . $langs->trans("Modify") . '">';
$out .= '</form>';
} else {
if (isset($selected)) {
$this->load_cache_rule_for_lines_dates();
if (isset($this->cache_rule_for_lines_dates[$selected])) {
$label = $this->cache_rule_for_lines_dates[$selected];
$out .= $langs->trans($label);
}
} else {
$out .= '&nbsp;';
}
}

if (empty($nooutput)) {
print $out;
return '';
}

return $out;
}

/**
* Show a form to select a delivery delay
*
Expand Down
1 change: 1 addition & 0 deletions htdocs/install/mysql/migration/20.0.0-21.0.0.sql
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,7 @@ INSERT INTO llx_c_type_contact (element, source, code, libelle, active ) values
INSERT INTO llx_c_type_contact (element, source, code, libelle, active ) values ('expedition', 'external', 'SHIPPING', 'Customer shipping contact', 1);

ALTER TABLE llx_facture_rec ADD COLUMN fk_societe_rib integer DEFAULT NULL;
ALTER TABLE llx_facture_rec ADD COLUMN rule_for_lines_dates varchar(255) DEFAULT 'prepaid';

ALTER TABLE llx_facture ADD COLUMN is_also_delivery_note tinyint DEFAULT 0 NOT NULL;
ALTER TABLE llx_user MODIFY COLUMN signature LONGTEXT;
7 changes: 4 additions & 3 deletions htdocs/install/mysql/tables/llx_facture_rec.sql
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,10 @@ create table llx_facture_rec
multicurrency_total_tva double(24,8) DEFAULT 0,
multicurrency_total_ttc double(24,8) DEFAULT 0,

usenewprice integer DEFAULT 0, -- update invoice with current price of product instead of recorded price
frequency integer, -- frequency (for example: 3 for every 3 month)
unit_frequency varchar(2) DEFAULT 'm', -- 'm' for month (date_when must be a day <= 28), 'y' for year, ...
usenewprice integer DEFAULT 0, -- update invoice with current price of product instead of recorded price
frequency integer, -- frequency (for example: 3 for every 3 month)
unit_frequency varchar(2) DEFAULT 'm', -- 'm' for month (date_when must be a day <= 28), 'y' for year, ...
rule_for_lines_dates varchar(255) DEFAULT 'prepaid',

date_when datetime DEFAULT NULL, -- date for next gen (when an invoice is generated, this field must be updated with next date)
date_last_gen datetime DEFAULT NULL, -- date for last gen (date with last successfull generation of invoice)
Expand Down
Loading