Merge branch 'develop' into ptibogxiv-stripe
This commit is contained in:
commit
3a8c216ab6
@ -882,7 +882,7 @@ if (empty($action) || $action == 'view') {
|
||||
else print $accountoshow;
|
||||
print '</td>';
|
||||
print "<td>" . $companystatic->getNomUrl(0, 'supplier', 16) . ' - ' . $invoicestatic->ref_supplier . ' - ' . $langs->trans("SubledgerAccount") . "</td>";
|
||||
print '<td align="right">' . ($mt < 0 ? - price(- $mt) : '') . "</td>";
|
||||
print '<td align="right">'. ($mt < 0 ? price(- $mt) : '') . "</td>";
|
||||
print '<td align="right">' . ($mt >= 0 ? price($mt) : '') . "</td>";
|
||||
print "</tr>";
|
||||
//}
|
||||
@ -976,7 +976,7 @@ if (empty($action) || $action == 'view') {
|
||||
print "<td>";
|
||||
print '</td>';
|
||||
print "<td>" . $companystatic->getNomUrl(0, 'supplier', 16) . ' - ' . $invoicestatic->ref_supplier . ' - ' . $langs->trans("VAT") . " NPR (counterpart)</td>";
|
||||
print '<td align="right">' . ($mt < 0 ? - price(- $mt) : '') . "</td>";
|
||||
print '<td align="right">' . ($mt < 0 ? price(- $mt) : '') . "</td>";
|
||||
print '<td align="right">' . ($mt >= 0 ? price($mt) : '') . "</td>";
|
||||
print "</tr>";
|
||||
}
|
||||
|
||||
@ -33,7 +33,7 @@
|
||||
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
|
||||
require_once DOL_DOCUMENT_ROOT . '/categories/class/categorie.class.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
|
||||
|
||||
|
||||
/**
|
||||
@ -1429,8 +1429,8 @@ class Adherent extends CommonObject
|
||||
$result=$customer->create_from_member($this, $companyname, $companyalias);
|
||||
if ($result < 0)
|
||||
{
|
||||
$this->error = $company->error;
|
||||
$this->errors = $company->errors;
|
||||
$this->error = $customer->error;
|
||||
$this->errors = $customer->errors;
|
||||
$error++;
|
||||
}
|
||||
else
|
||||
@ -1602,8 +1602,9 @@ class Adherent extends CommonObject
|
||||
// Define output language
|
||||
$outputlangs = $langs;
|
||||
$newlang = '';
|
||||
if ($conf->global->MAIN_MULTILANGS && empty($newlang) && ! empty($_REQUEST['lang_id']))
|
||||
$newlang = $_REQUEST['lang_id'];
|
||||
$lang_id=GETPOST('lang_id');
|
||||
if ($conf->global->MAIN_MULTILANGS && empty($newlang) && ! empty($lang_id))
|
||||
$newlang = $lang_id;
|
||||
if ($conf->global->MAIN_MULTILANGS && empty($newlang))
|
||||
$newlang = $customer->default_lang;
|
||||
if (! empty($newlang)) {
|
||||
|
||||
@ -195,7 +195,7 @@ else if ($action == 'setoptions')
|
||||
|
||||
$dirmodels=array_merge(array('/'),(array) $conf->modules_parts['models']);
|
||||
|
||||
llxHeader();
|
||||
llxHeader('',$langs->trans("ExpenseReportsSetup"));
|
||||
|
||||
$form=new Form($db);
|
||||
|
||||
|
||||
@ -67,7 +67,7 @@ require DOL_DOCUMENT_ROOT.'/core/actions_extrafields.inc.php';
|
||||
|
||||
$textobject=$langs->transnoentitiesnoconv("expensereports");
|
||||
|
||||
llxHeader('',$langs->trans("expensereportsSetup"));
|
||||
llxHeader('',$langs->trans("ExpenseReportsSetup"));
|
||||
|
||||
$linkback='<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
|
||||
print load_fiche_titre($langs->trans("ExpenseReportsSetup"),$linkback,'title_setup');
|
||||
|
||||
@ -58,12 +58,12 @@ if ($action == 'updateik')
|
||||
$result = $expIk->fetch($id);
|
||||
if ($result < 0) dol_print_error('', $expIk->error, $expIk->errors);
|
||||
}
|
||||
|
||||
|
||||
$expIk->setValues($_POST);
|
||||
$result = $expIk->create($user);
|
||||
|
||||
|
||||
if ($result > 0) setEventMessages('SetupSaved', null, 'mesgs');
|
||||
|
||||
|
||||
header('Location: '.$_SERVER['PHP_SELF']);
|
||||
exit;
|
||||
}
|
||||
@ -74,11 +74,11 @@ elseif ($action == 'delete') // TODO add confirm
|
||||
{
|
||||
$result = $expIk->fetch($id);
|
||||
if ($result < 0) dol_print_error('', $expIk->error, $expIk->errors);
|
||||
|
||||
|
||||
$expIk->delete($user);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
header('Location: '.$_SERVER['PHP_SELF']);
|
||||
exit;
|
||||
}
|
||||
@ -89,7 +89,7 @@ $rangesbycateg = ExpenseReportIk::getAllRanges();
|
||||
* View
|
||||
*/
|
||||
|
||||
llxHeader();
|
||||
llxHeader('',$langs->trans("ExpenseReportsSetup"));
|
||||
|
||||
$form=new Form($db);
|
||||
|
||||
@ -125,23 +125,23 @@ foreach ($rangesbycateg as $fk_c_exp_tax_cat => $Tab)
|
||||
echo '<td>'.$langs->trans('expenseReportTotalForFive').'</td>';
|
||||
echo '<td> </td>';
|
||||
echo '</tr>';
|
||||
|
||||
|
||||
if ($Tab['active'] == 0) continue;
|
||||
|
||||
|
||||
$tranche=1;
|
||||
$var = true;
|
||||
foreach ($Tab['ranges'] as $k => $range)
|
||||
{
|
||||
if (isset($Tab['ranges'][$k+1])) $label = $langs->trans('expenseReportRangeFromTo', $range->range_ik, ($Tab['ranges'][$k+1]->range_ik-1));
|
||||
else $label = $langs->trans('expenseReportRangeMoreThan', $range->range_ik);
|
||||
|
||||
|
||||
if ($range->range_active == 0) $label = $form->textwithpicto($label, $langs->trans('expenseReportRangeDisabled'), 1, 'help', '', 0, 3);
|
||||
|
||||
|
||||
echo '<tr '.$bc[$var].'>';
|
||||
|
||||
|
||||
// Label
|
||||
echo '<td width="20%"><b>['.$langs->trans('RangeNum', $tranche++).']</b> - '.$label.'</td>';
|
||||
|
||||
|
||||
// Offset
|
||||
echo '<td width="20%">';
|
||||
if ($action == 'edit' && $range->ik->id == $id && $range->rowid == $fk_range && $range->fk_c_exp_tax_cat == $fk_c_exp_tax_cat) echo '<input type="text" name="offset" value="'.$range->ik->offset.'" />';
|
||||
@ -152,10 +152,10 @@ foreach ($rangesbycateg as $fk_c_exp_tax_cat => $Tab)
|
||||
if ($action == 'edit' && $range->ik->id == $id && $range->rowid == $fk_range && $range->fk_c_exp_tax_cat == $fk_c_exp_tax_cat) echo '<input type="text" name="coef" value="'.$range->ik->coef.'" />';
|
||||
else echo ($range->ik->id > 0 ? $range->ik->coef : $langs->trans('expenseReportCoefUndefined'));
|
||||
echo '</td>';
|
||||
|
||||
|
||||
// Total for one
|
||||
echo '<td width="30%">'.$langs->trans('expenseReportPrintExample', price($range->ik->offset + 5 * $range->ik->coef)).'</td>';
|
||||
|
||||
|
||||
// Action
|
||||
echo '<td align="right">';
|
||||
if ($range->range_active == 1)
|
||||
@ -173,7 +173,7 @@ foreach ($rangesbycateg as $fk_c_exp_tax_cat => $Tab)
|
||||
}
|
||||
}
|
||||
echo '</td>';
|
||||
|
||||
|
||||
echo '</tr>';
|
||||
$var=!$var;
|
||||
}
|
||||
|
||||
@ -57,17 +57,17 @@ $amount = GETPOST('amount');
|
||||
$restrictive = GETPOST('restrictive');
|
||||
|
||||
$object = new ExpenseReportRule($db);
|
||||
if (!empty($id))
|
||||
if (!empty($id))
|
||||
{
|
||||
$result = $object->fetch($id);
|
||||
if ($result < 0) dol_print_error('', $object->error, $object->errors);
|
||||
}
|
||||
|
||||
|
||||
// TODO do action
|
||||
if ($action == 'save')
|
||||
{
|
||||
$error = 0;
|
||||
|
||||
|
||||
// check parameters
|
||||
if (empty($apply_to)) {
|
||||
$error++;
|
||||
@ -93,11 +93,11 @@ if ($action == 'save')
|
||||
$error++;
|
||||
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("ExpenseReportLimitAmount")), null, 'errors');
|
||||
}
|
||||
|
||||
|
||||
if (empty($error))
|
||||
{
|
||||
$object->setValues($_POST);
|
||||
|
||||
|
||||
if($apply_to=='U'){
|
||||
$object->fk_user=$fk_user;
|
||||
$object->fk_usergroup=0;
|
||||
@ -114,13 +114,13 @@ if ($action == 'save')
|
||||
|
||||
$object->dates = $dates;
|
||||
$object->datee = $datee;
|
||||
|
||||
|
||||
$object->entity = $conf->entity;
|
||||
|
||||
$res = $object->create($user);
|
||||
if ($res > 0) setEventMessages($langs->trans('ExpenseReportRuleSave'), null);
|
||||
else dol_print_error($object->db);
|
||||
|
||||
|
||||
header('Location: '.$_SERVER['PHP_SELF']);
|
||||
exit;
|
||||
}
|
||||
@ -129,7 +129,7 @@ elseif ($action == 'delete')
|
||||
{
|
||||
// TODO add confirm
|
||||
$res = $object->delete($user);
|
||||
|
||||
|
||||
if ($res < 0) dol_print_error($object->db);
|
||||
|
||||
header('Location: '.$_SERVER['PHP_SELF']);
|
||||
@ -145,7 +145,7 @@ $tab_rules_type = array('EX_DAY' => $langs->trans('Day'), 'EX_MON' => $langs->tr
|
||||
* View
|
||||
*/
|
||||
|
||||
llxHeader();
|
||||
llxHeader('',$langs->trans("ExpenseReportsSetup"));
|
||||
|
||||
$form=new Form($db);
|
||||
|
||||
@ -194,7 +194,7 @@ if ($action != 'edit')
|
||||
echo '</tr>';
|
||||
|
||||
echo '</table>';
|
||||
echo '</form>';
|
||||
echo '</form>';
|
||||
}
|
||||
|
||||
|
||||
@ -224,7 +224,7 @@ $var=true;
|
||||
foreach ($rules as $rule)
|
||||
{
|
||||
echo '<tr '.$bc[$var].'>';
|
||||
|
||||
|
||||
echo '<td>';
|
||||
if ($action == 'edit' && $object->id == $rule->id)
|
||||
{
|
||||
@ -240,8 +240,8 @@ foreach ($rules as $rule)
|
||||
elseif ($rule->fk_user > 0) echo $tab_apply['U'].' ('.$rule->getUserName().')';
|
||||
}
|
||||
echo '</td>';
|
||||
|
||||
|
||||
|
||||
|
||||
echo '<td>';
|
||||
if ($action == 'edit' && $object->id == $rule->id)
|
||||
{
|
||||
@ -250,7 +250,7 @@ foreach ($rules as $rule)
|
||||
else
|
||||
{
|
||||
if ($rule->fk_c_type_fees == -1) echo $langs->trans('AllExpenseReport');
|
||||
else
|
||||
else
|
||||
{
|
||||
$key = getDictvalue(MAIN_DB_PREFIX.'c_type_fees', 'code', $rule->fk_c_type_fees, false, 'id');
|
||||
if ($key != $langs->trans($key)) echo $langs->trans($key);
|
||||
@ -258,9 +258,9 @@ foreach ($rules as $rule)
|
||||
}
|
||||
}
|
||||
echo '</td>';
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
echo '<td>';
|
||||
if ($action == 'edit' && $object->id == $rule->id)
|
||||
{
|
||||
@ -271,8 +271,8 @@ foreach ($rules as $rule)
|
||||
echo $tab_rules_type[$rule->code_expense_rules_type];
|
||||
}
|
||||
echo '</td>';
|
||||
|
||||
|
||||
|
||||
|
||||
echo '<td>';
|
||||
if ($action == 'edit' && $object->id == $rule->id)
|
||||
{
|
||||
@ -283,8 +283,8 @@ foreach ($rules as $rule)
|
||||
echo dol_print_date($rule->dates, 'day');
|
||||
}
|
||||
echo '</td>';
|
||||
|
||||
|
||||
|
||||
|
||||
echo '<td>';
|
||||
if ($action == 'edit' && $object->id == $rule->id)
|
||||
{
|
||||
@ -295,8 +295,8 @@ foreach ($rules as $rule)
|
||||
echo dol_print_date($rule->datee, 'day');
|
||||
}
|
||||
echo '</td>';
|
||||
|
||||
|
||||
|
||||
|
||||
echo '<td>';
|
||||
if ($action == 'edit' && $object->id == $rule->id)
|
||||
{
|
||||
@ -307,8 +307,8 @@ foreach ($rules as $rule)
|
||||
echo price($rule->amount, 0, $langs, 1, -1, -1, $conf->currency);
|
||||
}
|
||||
echo '</td>';
|
||||
|
||||
|
||||
|
||||
|
||||
echo '<td>';
|
||||
if ($action == 'edit' && $object->id == $rule->id)
|
||||
{
|
||||
@ -319,8 +319,8 @@ foreach ($rules as $rule)
|
||||
echo yn($rule->restrictive, 1, 1);
|
||||
}
|
||||
echo '</td>';
|
||||
|
||||
|
||||
|
||||
|
||||
echo '<td>';
|
||||
if ($object->id != $rule->id)
|
||||
{
|
||||
@ -333,7 +333,7 @@ foreach ($rules as $rule)
|
||||
echo '<a href="'.$_SERVER['PHP_SELF'].'" class="button">'.$langs->trans('Cancel').'</a>';
|
||||
}
|
||||
echo '</td>';
|
||||
|
||||
|
||||
echo '</tr>';
|
||||
$var=!$var;
|
||||
}
|
||||
@ -355,9 +355,9 @@ echo '<script type="text/javascript"> $(function() {
|
||||
$("#user").hide();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
$("#apply_to").change();
|
||||
|
||||
|
||||
}); </script>';
|
||||
|
||||
dol_fiche_end();
|
||||
|
||||
@ -79,6 +79,10 @@ if ($action == 'update' && empty($_POST["cancel"]))
|
||||
dolibarr_set_const($db, "MAIN_MAIL_SMTPS_PW", GETPOST("MAIN_MAIL_SMTPS_PW"), 'chaine',0,'',$conf->entity);
|
||||
dolibarr_set_const($db, "MAIN_MAIL_EMAIL_TLS", GETPOST("MAIN_MAIL_EMAIL_TLS"),'chaine',0,'',$conf->entity);
|
||||
dolibarr_set_const($db, "MAIN_MAIL_EMAIL_STARTTLS", GETPOST("MAIN_MAIL_EMAIL_STARTTLS"),'chaine',0,'',$conf->entity);
|
||||
dolibarr_set_const($db, "MAIN_MAIL_EMAIL_DKIM_ENABLED", GETPOST("MAIN_MAIL_EMAIL_DKIM_ENABLED"),'chaine',0,'',$conf->entity);
|
||||
dolibarr_set_const($db, "MAIN_MAIL_EMAIL_DKIM_DOMAIN", GETPOST("MAIN_MAIL_EMAIL_DKIM_DOMAIN"),'chaine',0,'',$conf->entity);
|
||||
dolibarr_set_const($db, "MAIN_MAIL_EMAIL_DKIM_SELECTOR", GETPOST("MAIN_MAIL_EMAIL_DKIM_SELECTOR"),'chaine',0,'',$conf->entity);
|
||||
dolibarr_set_const($db, "MAIN_MAIL_EMAIL_DKIM_PRIVATE_KEY", GETPOST("MAIN_MAIL_EMAIL_DKIM_PRIVATE_KEY"),'chaine',0,'',$conf->entity);
|
||||
// Content parameters
|
||||
dolibarr_set_const($db, "MAIN_MAIL_EMAIL_FROM", GETPOST("MAIN_MAIL_EMAIL_FROM"), 'chaine',0,'',$conf->entity);
|
||||
dolibarr_set_const($db, "MAIN_MAIL_ERRORS_TO", GETPOST("MAIN_MAIL_ERRORS_TO"), 'chaine',0,'',$conf->entity);
|
||||
@ -152,26 +156,32 @@ if ($action == 'edit')
|
||||
jQuery("#MAIN_MAIL_EMAIL_TLS").prop("disabled", true);
|
||||
jQuery("#MAIN_MAIL_EMAIL_STARTTLS").val(0);
|
||||
jQuery("#MAIN_MAIL_EMAIL_STARTTLS").prop("disabled", true);
|
||||
jQuery("#MAIN_MAIL_EMAIL_DKIM_ENABLED").val(0);
|
||||
jQuery("#MAIN_MAIL_EMAIL_DKIM_ENABLED").prop("disabled", true);
|
||||
jQuery("#MAIN_MAIL_EMAIL_DKIM_DOMAIN").prop("disabled", true);
|
||||
jQuery("#MAIN_MAIL_EMAIL_DKIM_SELECTOR").prop("disabled", true);
|
||||
jQuery("#MAIN_MAIL_EMAIL_DKIM_PRIVATE_KEY").prop("disabled", true);
|
||||
jQuery("#MAIN_MAIL_EMAIL_DKIM_DOMAIN").hide();
|
||||
jQuery("#MAIN_MAIL_EMAIL_DKIM_SELECTOR").hide();
|
||||
jQuery("#MAIN_MAIL_EMAIL_DKIM_PRIVATE_KEY").hide();
|
||||
';
|
||||
if ($linuxlike)
|
||||
{
|
||||
print '
|
||||
jQuery("#MAIN_MAIL_SMTP_SERVER").hide();
|
||||
jQuery("#MAIN_MAIL_SMTP_PORT").hide();
|
||||
jQuery("#smtp_server_mess").show();
|
||||
jQuery("#smtp_port_mess").show();
|
||||
';
|
||||
jQuery("#MAIN_MAIL_SMTP_SERVER").hide();
|
||||
jQuery("#MAIN_MAIL_SMTP_PORT").hide();
|
||||
jQuery("#smtp_server_mess").show();
|
||||
jQuery("#smtp_port_mess").show();';
|
||||
}
|
||||
else
|
||||
{
|
||||
print '
|
||||
jQuery("#MAIN_MAIL_SMTP_SERVER").prop("disabled", true);
|
||||
jQuery("#MAIN_MAIL_SMTP_PORT").prop("disabled", true);
|
||||
jQuery("#smtp_server_mess").hide();
|
||||
jQuery("#smtp_port_mess").hide();
|
||||
';
|
||||
}
|
||||
print '
|
||||
print '
|
||||
jQuery("#MAIN_MAIL_SMTP_SERVER").prop("disabled", true);
|
||||
jQuery("#MAIN_MAIL_SMTP_PORT").prop("disabled", true);
|
||||
jQuery("#smtp_server_mess").hide();
|
||||
jQuery("#smtp_port_mess").hide();';
|
||||
}
|
||||
print '
|
||||
}
|
||||
if (jQuery("#MAIN_MAIL_SENDMODE").val()==\'smtps\')
|
||||
{
|
||||
@ -180,6 +190,14 @@ if ($action == 'edit')
|
||||
jQuery("#MAIN_MAIL_EMAIL_TLS").removeAttr("disabled");
|
||||
jQuery("#MAIN_MAIL_EMAIL_STARTTLS").val('.$conf->global->MAIN_MAIL_EMAIL_STARTTLS.');
|
||||
jQuery("#MAIN_MAIL_EMAIL_STARTTLS").removeAttr("disabled");
|
||||
jQuery("#MAIN_MAIL_EMAIL_DKIM_ENABLED").val(0);
|
||||
jQuery("#MAIN_MAIL_EMAIL_DKIM_ENABLED").prop("disabled", true);
|
||||
jQuery("#MAIN_MAIL_EMAIL_DKIM_DOMAIN").prop("disabled", true);
|
||||
jQuery("#MAIN_MAIL_EMAIL_DKIM_SELECTOR").prop("disabled", true);
|
||||
jQuery("#MAIN_MAIL_EMAIL_DKIM_PRIVATE_KEY").prop("disabled", true);
|
||||
jQuery("#MAIN_MAIL_EMAIL_DKIM_DOMAIN").hide();
|
||||
jQuery("#MAIN_MAIL_EMAIL_DKIM_SELECTOR").hide();
|
||||
jQuery("#MAIN_MAIL_EMAIL_DKIM_PRIVATE_KEY").hide();
|
||||
jQuery("#MAIN_MAIL_SMTP_SERVER").removeAttr("disabled");
|
||||
jQuery("#MAIN_MAIL_SMTP_PORT").removeAttr("disabled");
|
||||
jQuery("#MAIN_MAIL_SMTP_SERVER").show();
|
||||
@ -194,6 +212,14 @@ if ($action == 'edit')
|
||||
jQuery("#MAIN_MAIL_EMAIL_TLS").removeAttr("disabled");
|
||||
jQuery("#MAIN_MAIL_EMAIL_STARTTLS").val('.$conf->global->MAIN_MAIL_EMAIL_STARTTLS.');
|
||||
jQuery("#MAIN_MAIL_EMAIL_STARTTLS").removeAttr("disabled");
|
||||
jQuery("#MAIN_MAIL_EMAIL_DKIM_ENABLED").val('.$conf->global->MAIN_MAIL_EMAIL_DKIM_ENABLED.');
|
||||
jQuery("#MAIN_MAIL_EMAIL_DKIM_ENABLED").removeAttr("disabled");
|
||||
jQuery("#MAIN_MAIL_EMAIL_DKIM_DOMAIN").removeAttr("disabled");
|
||||
jQuery("#MAIN_MAIL_EMAIL_DKIM_SELECTOR").removeAttr("disabled");
|
||||
jQuery("#MAIN_MAIL_EMAIL_DKIM_PRIVATE_KEY").removeAttr("disabled");
|
||||
jQuery("#MAIN_MAIL_EMAIL_DKIM_DOMAIN").show();
|
||||
jQuery("#MAIN_MAIL_EMAIL_DKIM_SELECTOR").show();
|
||||
jQuery("#MAIN_MAIL_EMAIL_DKIM_PRIVATE_KEY").show();
|
||||
jQuery("#MAIN_MAIL_SMTP_SERVER").removeAttr("disabled");
|
||||
jQuery("#MAIN_MAIL_SMTP_PORT").removeAttr("disabled");
|
||||
jQuery("#MAIN_MAIL_SMTP_SERVER").show();
|
||||
@ -206,16 +232,16 @@ if ($action == 'edit')
|
||||
jQuery("#MAIN_MAIL_SENDMODE").change(function() {
|
||||
initfields();
|
||||
});
|
||||
jQuery("#MAIN_MAIL_EMAIL_TLS").change(function() {
|
||||
jQuery("#MAIN_MAIL_EMAIL_TLS").change(function() {
|
||||
if (jQuery("#MAIN_MAIL_EMAIL_STARTTLS").val() == 1)
|
||||
jQuery("#MAIN_MAIL_EMAIL_STARTTLS").val(0);
|
||||
});
|
||||
jQuery("#MAIN_MAIL_EMAIL_STARTTLS").change(function() {
|
||||
if (jQuery("#MAIN_MAIL_EMAIL_TLS").val() == 1)
|
||||
jQuery("#MAIN_MAIL_EMAIL_TLS").val(0);
|
||||
});
|
||||
});
|
||||
})';
|
||||
print '</script>'."\n";
|
||||
print '</script>'."\n";
|
||||
}
|
||||
|
||||
print '<form method="post" action="'.$_SERVER["PHP_SELF"].'">';
|
||||
@ -374,9 +400,9 @@ if ($action == 'edit')
|
||||
print '</td></tr>';
|
||||
}
|
||||
|
||||
// TLS
|
||||
// TLS
|
||||
|
||||
print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_EMAIL_TLS").'</td><td>';
|
||||
print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_EMAIL_TLS").'</td><td>';
|
||||
if (! empty($conf->use_javascript_ajax) || (isset($conf->global->MAIN_MAIL_SENDMODE) && in_array($conf->global->MAIN_MAIL_SENDMODE, array('smtps', 'swiftmailer'))))
|
||||
{
|
||||
if (function_exists('openssl_open'))
|
||||
@ -389,7 +415,6 @@ if ($action == 'edit')
|
||||
print '</td></tr>';
|
||||
|
||||
// STARTTLS
|
||||
|
||||
print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_EMAIL_STARTTLS").'</td><td>';
|
||||
if (! empty($conf->use_javascript_ajax) || (isset($conf->global->MAIN_MAIL_SENDMODE) && in_array($conf->global->MAIN_MAIL_SENDMODE, array('smtps', 'swiftmailer'))))
|
||||
{
|
||||
@ -402,8 +427,35 @@ if ($action == 'edit')
|
||||
else print yn(0).' ('.$langs->trans("NotSupported").')';
|
||||
print '</td></tr>';
|
||||
|
||||
// Separator
|
||||
// DKIM
|
||||
print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_EMAIL_DKIM_ENABLED").'</td><td>';
|
||||
if (! empty($conf->use_javascript_ajax) || (isset($conf->global->MAIN_MAIL_SENDMODE) && in_array($conf->global->MAIN_MAIL_SENDMODE, array('swiftmailer'))))
|
||||
{
|
||||
if (function_exists('openssl_open'))
|
||||
{
|
||||
print $form->selectyesno('MAIN_MAIL_EMAIL_DKIM_ENABLED',(! empty($conf->global->MAIN_MAIL_EMAIL_DKIM_ENABLED)?$conf->global->MAIN_MAIL_EMAIL_DKIM_ENABLED:0),1);
|
||||
}
|
||||
else print yn(0).' ('.$langs->trans("YourPHPDoesNotHaveSSLSupport").')';
|
||||
}
|
||||
else print yn(0).' ('.$langs->trans("NotSupported").')';
|
||||
print '</td></tr>';
|
||||
|
||||
// Domain
|
||||
print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_EMAIL_DKIM_DOMAIN").'</td>';
|
||||
print '<td><input class="flat" id="MAIN_MAIL_EMAIL_DKIM_DOMAIN" name="MAIN_MAIL_EMAIL_DKIM_DOMAIN" size="32" value="' . (! empty($conf->global->MAIN_MAIL_EMAIL_DKIM_DOMAIN)?$conf->global->MAIN_MAIL_EMAIL_DKIM_DOMAIN:'');
|
||||
print '"></td></tr>';
|
||||
|
||||
// Selector
|
||||
print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_EMAIL_DKIM_SELECTOR").'</td>';
|
||||
print '<td><input class="flat" id="MAIN_MAIL_EMAIL_DKIM_SELECTOR" name="MAIN_MAIL_EMAIL_DKIM_SELECTOR" size="32" value="' . (! empty($conf->global->MAIN_MAIL_EMAIL_DKIM_SELECTOR)?$conf->global->MAIN_MAIL_EMAIL_DKIM_SELECTOR:'');
|
||||
print '"></td></tr>';
|
||||
|
||||
// PRIVATE KEY
|
||||
print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_EMAIL_DKIM_PRIVATE_KEY").'</td>';
|
||||
print '<td><textarea id="MAIN_MAIL_EMAIL_DKIM_PRIVATE_KEY" name="MAIN_MAIL_EMAIL_DKIM_PRIVATE_KEY" rows="15" cols="100">' . (! empty($conf->global->MAIN_MAIL_EMAIL_DKIM_PRIVATE_KEY)?$conf->global->MAIN_MAIL_EMAIL_DKIM_PRIVATE_KEY:'').'</textarea>';
|
||||
print '</td></tr>';
|
||||
|
||||
// Separator
|
||||
print '<tr class="oddeven"><td colspan="2"> </td></tr>';
|
||||
|
||||
// From
|
||||
@ -565,7 +617,36 @@ else
|
||||
else print yn(0).' ('.$langs->trans("NotSupported").')';
|
||||
print '</td></tr>';
|
||||
|
||||
// Separator
|
||||
// DKIM
|
||||
|
||||
print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_EMAIL_DKIM_ENABLED").'</td><td>';
|
||||
if (isset($conf->global->MAIN_MAIL_SENDMODE) && in_array($conf->global->MAIN_MAIL_SENDMODE, array('swiftmailer')))
|
||||
{
|
||||
if (function_exists('openssl_open'))
|
||||
{
|
||||
print yn($conf->global->MAIN_MAIL_EMAIL_DKIM_ENABLED);
|
||||
}
|
||||
else print yn(0).' ('.$langs->trans("YourPHPDoesNotHaveSSLSupport").')';
|
||||
}
|
||||
else print yn(0).' ('.$langs->trans("NotSupported").')';
|
||||
print '</td></tr>';
|
||||
|
||||
// Domain
|
||||
print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_EMAIL_DKIM_DOMAIN").'</td>';
|
||||
print '<td>' . $conf->global->MAIN_MAIL_EMAIL_DKIM_DOMAIN;
|
||||
print '</td></tr>';
|
||||
|
||||
// Selector
|
||||
print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_EMAIL_DKIM_SELECTOR").'</td>';
|
||||
print '<td>' . $conf->global->MAIN_MAIL_EMAIL_DKIM_SELECTOR;
|
||||
print '</td></tr>';
|
||||
|
||||
// PRIVATE KEY
|
||||
print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_EMAIL_DKIM_PRIVATE_KEY").'</td>';
|
||||
print '<td>' . $conf->global->MAIN_MAIL_EMAIL_DKIM_PRIVATE_KEY;
|
||||
print '</td></tr>';
|
||||
|
||||
// Separator
|
||||
|
||||
print '<tr class="oddeven"><td colspan="2"> </td></tr>';
|
||||
|
||||
|
||||
@ -95,6 +95,7 @@ print '<table class="noborder" width="100%">';
|
||||
|
||||
$i=0;
|
||||
|
||||
// $list is defined into oauth.lib.php
|
||||
foreach ($list as $key)
|
||||
{
|
||||
$supported=0;
|
||||
|
||||
@ -141,13 +141,27 @@ if ($mode == 'setup' && $user->admin)
|
||||
$urltodelete=$urlwithroot.'/core/modules/oauth/github_oauthcallback.php?action=delete&backtourl='.urlencode(DOL_URL_ROOT.'/admin/oauthlogintokens.php');
|
||||
$urltocheckperms='https://github.com/settings/applications/';
|
||||
}
|
||||
if ($key[0] == 'OAUTH_GOOGLE_NAME')
|
||||
elseif ($key[0] == 'OAUTH_GOOGLE_NAME')
|
||||
{
|
||||
$OAUTH_SERVICENAME='Google';
|
||||
$urltorenew=$urlwithroot.'/core/modules/oauth/google_oauthcallback.php?state=userinfo_email,userinfo_profile,cloud_print&backtourl='.urlencode(DOL_URL_ROOT.'/admin/oauthlogintokens.php');
|
||||
$urltodelete=$urlwithroot.'/core/modules/oauth/google_oauthcallback.php?action=delete&backtourl='.urlencode(DOL_URL_ROOT.'/admin/oauthlogintokens.php');
|
||||
$urltocheckperms='https://security.google.com/settings/security/permissions';
|
||||
}
|
||||
elseif ($key[0] == 'OAUTH_STRIPE_TEST_NAME')
|
||||
{
|
||||
$OAUTH_SERVICENAME='StripeTest';
|
||||
$urltorenew=$urlwithroot.'/core/modules/oauth/stripetest_oauthcallback.php?backtourl='.urlencode(DOL_URL_ROOT.'/admin/oauthlogintokens.php');
|
||||
$urltodelete='';
|
||||
$urltocheckperms='';
|
||||
}
|
||||
else
|
||||
{
|
||||
$urltorenew='';
|
||||
$urltodelete='';
|
||||
$urltocheckperms='';
|
||||
}
|
||||
|
||||
|
||||
// Show value of token
|
||||
$tokenobj=null;
|
||||
@ -204,7 +218,6 @@ if ($mode == 'setup' && $user->admin)
|
||||
|
||||
print '<table class="noborder" width="100%">'."\n";
|
||||
|
||||
$var=false;
|
||||
print '<tr class="liste_titre">';
|
||||
print '<th class="titlefieldcreate">'.$langs->trans($key[0]).'</th>';
|
||||
print '<th></th>';
|
||||
@ -222,7 +235,6 @@ if ($mode == 'setup' && $user->admin)
|
||||
print '</td>';
|
||||
print '</tr>'."\n";
|
||||
|
||||
$var = ! $var;
|
||||
print '<tr class="oddeven">';
|
||||
print '<td'.($key['required']?' class="required"':'').'>';
|
||||
//var_dump($key);
|
||||
@ -237,19 +249,21 @@ if ($mode == 'setup' && $user->admin)
|
||||
if (is_object($tokenobj))
|
||||
{
|
||||
//test on $storage->hasAccessToken($OAUTH_SERVICENAME) ?
|
||||
print '<a class="button" href="'.$urltodelete.'">'.$langs->trans('DeleteAccess').'</a><br><br>';
|
||||
print '<a class="button" href="'.$urltodelete.'">'.$langs->trans('DeleteAccess').'</a><br>';
|
||||
}
|
||||
// Request remote token
|
||||
print '<a class="button" href="'.$urltorenew.'">'.$langs->trans('RequestAccess').'</a><br><br>';
|
||||
if ($urltorenew)
|
||||
{
|
||||
print '<a class="button" href="'.$urltorenew.'">'.$langs->trans('RequestAccess').'</a><br>';
|
||||
}
|
||||
// Check remote access
|
||||
if ($urltocheckperms)
|
||||
{
|
||||
print $langs->trans("ToCheckDeleteTokenOnProvider", $OAUTH_SERVICENAME).': <a href="'.$urltocheckperms.'" target="_'.strtolower($OAUTH_SERVICENAME).'">'.$urltocheckperms.'</a>';
|
||||
print '<br>'.$langs->trans("ToCheckDeleteTokenOnProvider", $OAUTH_SERVICENAME).': <a href="'.$urltocheckperms.'" target="_'.strtolower($OAUTH_SERVICENAME).'">'.$urltocheckperms.'</a>';
|
||||
}
|
||||
print '</td>';
|
||||
print '</tr>';
|
||||
|
||||
$var = ! $var;
|
||||
print '<tr class="oddeven">';
|
||||
print '<td'.($key['required']?' class="required"':'').'>';
|
||||
//var_dump($key);
|
||||
@ -272,7 +286,6 @@ if ($mode == 'setup' && $user->admin)
|
||||
if (is_object($tokenobj))
|
||||
{
|
||||
// Token refresh
|
||||
$var = ! $var;
|
||||
print '<tr class="oddeven">';
|
||||
print '<td'.($key['required']?' class="required"':'').'>';
|
||||
//var_dump($key);
|
||||
@ -283,7 +296,6 @@ if ($mode == 'setup' && $user->admin)
|
||||
print '</tr>';
|
||||
|
||||
// Token expired
|
||||
$var = ! $var;
|
||||
print '<tr class="oddeven">';
|
||||
print '<td'.($key['required']?' class="required"':'').'>';
|
||||
//var_dump($key);
|
||||
@ -294,7 +306,6 @@ if ($mode == 'setup' && $user->admin)
|
||||
print '</tr>';
|
||||
|
||||
// Token expired at
|
||||
$var = ! $var;
|
||||
print '<tr class="oddeven">';
|
||||
print '<td'.($key['required']?' class="required"':'').'>';
|
||||
//var_dump($key);
|
||||
@ -354,7 +365,6 @@ if ($mode == 'userconf' && $user->admin)
|
||||
print $langs->trans('PrintUserConfDesc'.$driver)."<br><br>\n";
|
||||
|
||||
print '<table class="noborder" width="100%">';
|
||||
$var=true;
|
||||
print '<tr class="liste_titre">';
|
||||
print '<th>'.$langs->trans("User").'</th>';
|
||||
print '<th>'.$langs->trans("PrintModule").'</th>';
|
||||
|
||||
@ -146,6 +146,16 @@ if ($action == 'setlevel')
|
||||
dol_syslog("admin/syslog: level ".$level);
|
||||
|
||||
if (! $res > 0) $error++;
|
||||
|
||||
if (! $error)
|
||||
{
|
||||
$file_saves = GETPOST("file_saves");
|
||||
$res = dolibarr_set_const($db,"SYSLOG_FILE_SAVES",$file_saves,'chaine',0,'',0);
|
||||
dol_syslog("admin/syslog: file saves ".$file_saves);
|
||||
|
||||
if (! $res > 0) $error++;
|
||||
}
|
||||
|
||||
if (! $error)
|
||||
{
|
||||
setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
|
||||
@ -284,6 +294,13 @@ print '<option value="'.LOG_INFO.'" '.($conf->global->SYSLOG_LEVEL==LOG_INFO?'SE
|
||||
print '<option value="'.LOG_DEBUG.'" '.($conf->global->SYSLOG_LEVEL>=LOG_DEBUG?'SELECTED':'').'>LOG_DEBUG ('.LOG_DEBUG.')</option>';
|
||||
print '</select>';
|
||||
print '</td></tr>';
|
||||
|
||||
if(! empty($conf->loghandlers['mod_syslog_file']) && ! empty($conf->cron->enabled)) {
|
||||
print '<tr class="oddeven"><td width="140">'.$langs->trans("SyslogFileNumberOfSaves").'</td>';
|
||||
print '<td colspan="2"><input type="number" name="file_saves" placeholder="14" min="0" step="1" value="'.$conf->global->SYSLOG_FILE_SAVES.'" />';
|
||||
print ' (<a href="'.dol_buildpath('/cron/list.php', 1).'?search_label=CompressSyslogs&status=-1">'.$langs->trans('ConfigureCleaningCronjobToSetFrequencyOfSaves').'</a>)</td></tr>';
|
||||
}
|
||||
|
||||
print '</table>';
|
||||
print "</form>\n";
|
||||
|
||||
|
||||
@ -3,6 +3,7 @@
|
||||
* Copyright (C) 2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
|
||||
* Copyright (C) 2007-2012 Regis Houssin <regis.houssin@capnetworks.com>
|
||||
* Copyright (C) 2015 Frederic France <frederic.france@free.fr>
|
||||
* Copyright (C) 2017 Nicolas ZABOURI <info@inovea-conseil.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@ -39,6 +40,8 @@ $error=0;
|
||||
* View
|
||||
*/
|
||||
|
||||
@set_time_limit(300);
|
||||
|
||||
llxHeader();
|
||||
|
||||
print load_fiche_titre($langs->trans("FileCheckDolibarr"),'','title_setup');
|
||||
|
||||
@ -1,9 +1,9 @@
|
||||
<?php
|
||||
/* Copyright (C) 2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
|
||||
/* Copyright (C) 2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
|
||||
* Copyright (C) 2005-2016 Laurent Destailleur <eldy@users.sourceforge.org>
|
||||
* Copyright (C) 2011 Juanjo Menent <jmenent@2byte.es>
|
||||
* Copyright (C) 2012 Regis Houssin <regis.houssin@capnetworks.com>
|
||||
* Copyright (C) 2015 Jean-François Ferry <jfefe@aternatik.fr>
|
||||
* Copyright (C) 2012-2018 Regis Houssin <regis.houssin@capnetworks.com>
|
||||
* Copyright (C) 2015 Jean-François Ferry <jfefe@aternatik.fr>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@ -41,7 +41,7 @@ if ($action == 'setproductionmode')
|
||||
{
|
||||
$status = GETPOST('status','alpha');
|
||||
|
||||
if (dolibarr_set_const($db, 'API_PRODUCTION_MODE', $status, 'chaine', 0, '', $conf->entity) > 0)
|
||||
if (dolibarr_set_const($db, 'API_PRODUCTION_MODE', $status, 'chaine', 0, '', 0) > 0)
|
||||
{
|
||||
$error=0;
|
||||
|
||||
|
||||
@ -1204,6 +1204,8 @@ class Categorie extends CommonObject
|
||||
*/
|
||||
function get_all_categories($type=null, $parent=false)
|
||||
{
|
||||
if (! is_numeric($type)) $type = $this->MAP_ID[$type];
|
||||
|
||||
$sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."categorie";
|
||||
$sql.= " WHERE entity IN (".getEntity('category').")";
|
||||
if (! is_null($type))
|
||||
|
||||
@ -245,7 +245,9 @@ $next_day = $next['day'];
|
||||
|
||||
// Define firstdaytoshow and lastdaytoshow (warning: lastdaytoshow is last second to show + 1)
|
||||
$firstdaytoshow=dol_mktime(0,0,0,$first_month,$first_day,$first_year);
|
||||
$lastdaytoshow=dol_time_plus_duree($firstdaytoshow, 7, 'd');
|
||||
|
||||
$nb_weeks_to_show = !empty($conf->global->AGENDA_NB_WEEKS_IN_VIEW_PER_USER) ? (int)$conf->global->AGENDA_NB_WEEKS_IN_VIEW_PER_USER * 7 : 7;
|
||||
$lastdaytoshow=dol_time_plus_duree($firstdaytoshow, $nb_weeks_to_show, 'd');
|
||||
//print $firstday.'-'.$first_month.'-'.$first_year;
|
||||
//print dol_print_date($firstdaytoshow,'dayhour');
|
||||
//print dol_print_date($lastdaytoshow,'dayhour');
|
||||
@ -465,7 +467,7 @@ if ($filtert > 0 || $usergroup > 0)
|
||||
}
|
||||
// Sort on date
|
||||
$sql.= ' ORDER BY fk_user_action, datep'; //fk_user_action
|
||||
//print $sql;exit;
|
||||
|
||||
|
||||
dol_syslog("comm/action/peruser.php", LOG_DEBUG);
|
||||
$resql=$db->query($sql);
|
||||
@ -619,183 +621,193 @@ echo '<input type="hidden" name="newdate" id="newdate">' ;
|
||||
|
||||
//print "begin_d=".$begin_d." end_d=".$end_d;
|
||||
|
||||
|
||||
$currentdaytoshow = $firstdaytoshow;
|
||||
echo '<div class="div-table-responsive">';
|
||||
echo '<table width="100%" class="noborder nocellnopadd cal_month">';
|
||||
|
||||
echo '<tr class="liste_titre">';
|
||||
echo '<td></td>';
|
||||
$i=0; // 0 = sunday,
|
||||
while ($i < 7)
|
||||
{
|
||||
if (($i + 1) < $begin_d || ($i + 1) > $end_d)
|
||||
{
|
||||
$i++;
|
||||
continue;
|
||||
}
|
||||
echo '<td align="center" colspan="'.($end_h - $begin_h).'">';
|
||||
echo $langs->trans("Day".(($i+(isset($conf->global->MAIN_START_WEEK)?$conf->global->MAIN_START_WEEK:1)) % 7));
|
||||
print "<br>";
|
||||
if ($i) print dol_print_date(dol_time_plus_duree($firstdaytoshow, $i, 'd'),'day');
|
||||
else print dol_print_date($firstdaytoshow,'day');
|
||||
echo "</td>\n";
|
||||
$i++;
|
||||
}
|
||||
echo "</tr>\n";
|
||||
|
||||
echo '<tr class="liste_titre">';
|
||||
echo '<td></td>';
|
||||
$i=0;
|
||||
while ($i < 7)
|
||||
{
|
||||
if (($i + 1) < $begin_d || ($i + 1) > $end_d)
|
||||
{
|
||||
$i++;
|
||||
continue;
|
||||
}
|
||||
for ($h = $begin_h; $h < $end_h; $h++)
|
||||
{
|
||||
echo '<td align="center">';
|
||||
print '<small style="font-family: courier">'.sprintf("%02d",$h).'</small>';
|
||||
print "</td>";
|
||||
}
|
||||
echo "</td>\n";
|
||||
$i++;
|
||||
}
|
||||
echo "</tr>\n";
|
||||
|
||||
|
||||
// Define $usernames
|
||||
$usernames = array(); //init
|
||||
$usernamesid = array();
|
||||
/* Use this to have list of users only if users have events */
|
||||
if (! empty($conf->global->AGENDA_SHOWOWNERONLY_ONPERUSERVIEW))
|
||||
{
|
||||
foreach ($eventarray as $daykey => $notused)
|
||||
{
|
||||
// Get all assigned users for each event
|
||||
foreach ($eventarray[$daykey] as $index => $event)
|
||||
{
|
||||
$event->fetch_userassigned();
|
||||
$listofuserid=$event->userassigned;
|
||||
foreach($listofuserid as $userid => $tmp)
|
||||
{
|
||||
if (! in_array($userid, $usernamesid)) $usernamesid[$userid] = $userid;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/* Use this list to have for all users */
|
||||
else
|
||||
{
|
||||
$sql = "SELECT u.rowid, u.lastname as lastname, u.firstname, u.statut, u.login, u.admin, u.entity";
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX."user as u";
|
||||
if ($usergroup > 0) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."usergroup_user as ug ON u.rowid = ug.fk_user";
|
||||
$sql.= " WHERE u.statut = 1 AND u.entity IN (".getEntity('user').")";
|
||||
if ($usergroup > 0) $sql.= " AND ug.fk_usergroup = ".$usergroup;
|
||||
//print $sql;
|
||||
$resql=$db->query($sql);
|
||||
if ($resql)
|
||||
{
|
||||
$num = $db->num_rows($resql);
|
||||
$i = 0;
|
||||
if ($num)
|
||||
{
|
||||
while ($i < $num)
|
||||
{
|
||||
$obj = $db->fetch_object($resql);
|
||||
$usernamesid[$obj->rowid]=$obj->rowid;
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
else dol_print_error($db);
|
||||
}
|
||||
//var_dump($usernamesid);
|
||||
foreach($usernamesid as $id)
|
||||
{
|
||||
$tmpuser=new User($db);
|
||||
$result=$tmpuser->fetch($id);
|
||||
$usernames[]=$tmpuser;
|
||||
}
|
||||
|
||||
/*
|
||||
if ($filtert > 0)
|
||||
{
|
||||
$tmpuser = new User($db);
|
||||
$tmpuser->fetch($filtert);
|
||||
$usernames[] = $tmpuser;
|
||||
}
|
||||
else if ($usergroup)
|
||||
{
|
||||
$tmpgroup = new UserGroup($db);
|
||||
$tmpgroup->fetch($usergroup);
|
||||
$usernames = $tmpgroup->listUsersForGroup();
|
||||
}
|
||||
else
|
||||
{
|
||||
$tmpgroup = new UserGroup($db);
|
||||
//$tmpgroup->fetch($usergroup); No fetch, we want all users for all groups
|
||||
$usernames = $tmpgroup->listUsersForGroup();
|
||||
}*/
|
||||
|
||||
// Load array of colors by type
|
||||
$colorsbytype=array();
|
||||
$labelbytype=array();
|
||||
$sql="SELECT code, color, libelle FROM ".MAIN_DB_PREFIX."c_actioncomm ORDER BY position";
|
||||
$resql=$db->query($sql);
|
||||
while ($obj = $db->fetch_object($resql))
|
||||
{
|
||||
$colorsbytype[$obj->code]=$obj->color;
|
||||
$labelbytype[$obj->code]=$obj->libelle;
|
||||
}
|
||||
|
||||
// Loop on each user to show calendar
|
||||
$todayarray=dol_getdate($now,'fast');
|
||||
$sav = $tmpday;
|
||||
$showheader = true;
|
||||
$var = false;
|
||||
foreach ($usernames as $username)
|
||||
{
|
||||
$var = ! $var;
|
||||
echo "<tr>";
|
||||
echo '<td class="tdoverflowmax100 cal_current_month cal_peruserviewname'.($var?' cal_impair':'').'">';
|
||||
print $username->getNomUrl(-1,'',0,0,20,1,'');
|
||||
print '</td>';
|
||||
$tmpday = $sav;
|
||||
|
||||
// Lopp on each day of week
|
||||
$i = 0;
|
||||
for ($iter_day = 0; $iter_day < 8; $iter_day++)
|
||||
while($currentdaytoshow<$lastdaytoshow) {
|
||||
|
||||
echo '<table width="100%" class="noborder nocellnopadd cal_month">';
|
||||
|
||||
echo '<tr class="liste_titre">';
|
||||
echo '<td></td>';
|
||||
$i=0; // 0 = sunday,
|
||||
while ($i < 7)
|
||||
{
|
||||
if (($i + 1) < $begin_d || ($i + 1) > $end_d)
|
||||
{
|
||||
$i++;
|
||||
continue;
|
||||
}
|
||||
|
||||
// Show days of the current week
|
||||
$curtime = dol_time_plus_duree($firstdaytoshow, $iter_day, 'd');
|
||||
$tmparray = dol_getdate($curtime,'fast');
|
||||
$tmpday = $tmparray['mday'];
|
||||
$tmpmonth = $tmparray['mon'];
|
||||
$tmpyear = $tmparray['year'];
|
||||
|
||||
$style='cal_current_month';
|
||||
if ($iter_day == 6) $style.=' cal_other_month';
|
||||
$today=0;
|
||||
if ($todayarray['mday']==$tmpday && $todayarray['mon']==$tmpmonth && $todayarray['year']==$tmpyear) $today=1;
|
||||
if ($today) $style='cal_today_peruser';
|
||||
|
||||
show_day_events2($username, $tmpday, $tmpmonth, $tmpyear, $monthshown, $style, $eventarray, 0, $maxnbofchar, $newparam, 1, 300, $showheader, $colorsbytype, $var);
|
||||
|
||||
echo '<td align="center" colspan="'.($end_h - $begin_h).'">';
|
||||
echo $langs->trans("Day".(($i+(isset($conf->global->MAIN_START_WEEK)?$conf->global->MAIN_START_WEEK:1)) % 7));
|
||||
print "<br>";
|
||||
if ($i) print dol_print_date(dol_time_plus_duree($currentdaytoshow, $i, 'd'),'day');
|
||||
else print dol_print_date($currentdaytoshow,'day');
|
||||
echo "</td>\n";
|
||||
$i++;
|
||||
}
|
||||
echo "</tr>\n";
|
||||
$showheader = false;
|
||||
|
||||
echo '<tr class="liste_titre">';
|
||||
echo '<td></td>';
|
||||
$i=0;
|
||||
while ($i < 7)
|
||||
{
|
||||
if (($i + 1) < $begin_d || ($i + 1) > $end_d)
|
||||
{
|
||||
$i++;
|
||||
continue;
|
||||
}
|
||||
for ($h = $begin_h; $h < $end_h; $h++)
|
||||
{
|
||||
echo '<td align="center">';
|
||||
print '<small style="font-family: courier">'.sprintf("%02d",$h).'</small>';
|
||||
print "</td>";
|
||||
}
|
||||
echo "</td>\n";
|
||||
$i++;
|
||||
}
|
||||
echo "</tr>\n";
|
||||
|
||||
|
||||
// Define $usernames
|
||||
$usernames = array(); //init
|
||||
$usernamesid = array();
|
||||
/* Use this to have list of users only if users have events */
|
||||
if (! empty($conf->global->AGENDA_SHOWOWNERONLY_ONPERUSERVIEW))
|
||||
{
|
||||
foreach ($eventarray as $daykey => $notused)
|
||||
{
|
||||
// Get all assigned users for each event
|
||||
foreach ($eventarray[$daykey] as $index => $event)
|
||||
{
|
||||
$event->fetch_userassigned();
|
||||
$listofuserid=$event->userassigned;
|
||||
foreach($listofuserid as $userid => $tmp)
|
||||
{
|
||||
if (! in_array($userid, $usernamesid)) $usernamesid[$userid] = $userid;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/* Use this list to have for all users */
|
||||
else
|
||||
{
|
||||
$sql = "SELECT u.rowid, u.lastname as lastname, u.firstname, u.statut, u.login, u.admin, u.entity";
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX."user as u";
|
||||
if ($usergroup > 0) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."usergroup_user as ug ON u.rowid = ug.fk_user";
|
||||
$sql.= " WHERE u.statut = 1 AND u.entity IN (".getEntity('user').")";
|
||||
if ($usergroup > 0) $sql.= " AND ug.fk_usergroup = ".$usergroup;
|
||||
//print $sql;
|
||||
$resql=$db->query($sql);
|
||||
if ($resql)
|
||||
{
|
||||
$num = $db->num_rows($resql);
|
||||
$i = 0;
|
||||
if ($num)
|
||||
{
|
||||
while ($i < $num)
|
||||
{
|
||||
$obj = $db->fetch_object($resql);
|
||||
$usernamesid[$obj->rowid]=$obj->rowid;
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
else dol_print_error($db);
|
||||
}
|
||||
//var_dump($usernamesid);
|
||||
foreach($usernamesid as $id)
|
||||
{
|
||||
$tmpuser=new User($db);
|
||||
$result=$tmpuser->fetch($id);
|
||||
$usernames[]=$tmpuser;
|
||||
}
|
||||
|
||||
/*
|
||||
if ($filtert > 0)
|
||||
{
|
||||
$tmpuser = new User($db);
|
||||
$tmpuser->fetch($filtert);
|
||||
$usernames[] = $tmpuser;
|
||||
}
|
||||
else if ($usergroup)
|
||||
{
|
||||
$tmpgroup = new UserGroup($db);
|
||||
$tmpgroup->fetch($usergroup);
|
||||
$usernames = $tmpgroup->listUsersForGroup();
|
||||
}
|
||||
else
|
||||
{
|
||||
$tmpgroup = new UserGroup($db);
|
||||
//$tmpgroup->fetch($usergroup); No fetch, we want all users for all groups
|
||||
$usernames = $tmpgroup->listUsersForGroup();
|
||||
}*/
|
||||
|
||||
// Load array of colors by type
|
||||
$colorsbytype=array();
|
||||
$labelbytype=array();
|
||||
$sql="SELECT code, color, libelle FROM ".MAIN_DB_PREFIX."c_actioncomm ORDER BY position";
|
||||
$resql=$db->query($sql);
|
||||
while ($obj = $db->fetch_object($resql))
|
||||
{
|
||||
$colorsbytype[$obj->code]=$obj->color;
|
||||
$labelbytype[$obj->code]=$obj->libelle;
|
||||
}
|
||||
|
||||
// Loop on each user to show calendar
|
||||
$todayarray=dol_getdate($now,'fast');
|
||||
$sav = $tmpday;
|
||||
$showheader = true;
|
||||
$var = false;
|
||||
foreach ($usernames as $username)
|
||||
{
|
||||
$var = ! $var;
|
||||
echo "<tr>";
|
||||
echo '<td class="tdoverflowmax100 cal_current_month cal_peruserviewname'.($var?' cal_impair':'').'">';
|
||||
print $username->getNomUrl(-1,'',0,0,20,1,'');
|
||||
print '</td>';
|
||||
$tmpday = $sav;
|
||||
|
||||
// Lopp on each day of week
|
||||
$i = 0;
|
||||
for ($iter_day = 0; $iter_day < 8; $iter_day++)
|
||||
{
|
||||
|
||||
if (($i + 1) < $begin_d || ($i + 1) > $end_d)
|
||||
{
|
||||
$i++;
|
||||
continue;
|
||||
}
|
||||
|
||||
// Show days of the current week
|
||||
$curtime = dol_time_plus_duree($currentdaytoshow, $iter_day, 'd');
|
||||
$tmparray = dol_getdate($curtime,'fast');
|
||||
$tmpday = $tmparray['mday'];
|
||||
$tmpmonth = $tmparray['mon'];
|
||||
$tmpyear = $tmparray['year'];
|
||||
|
||||
$style='cal_current_month';
|
||||
if ($iter_day == 6) $style.=' cal_other_month';
|
||||
$today=0;
|
||||
if ($todayarray['mday']==$tmpday && $todayarray['mon']==$tmpmonth && $todayarray['year']==$tmpyear) $today=1;
|
||||
if ($today) $style='cal_today_peruser';
|
||||
|
||||
show_day_events2($username, $tmpday, $tmpmonth, $tmpyear, $monthshown, $style, $eventarray, 0, $maxnbofchar, $newparam, 1, 300, $showheader, $colorsbytype, $var);
|
||||
|
||||
$i++;
|
||||
}
|
||||
echo "</tr>\n";
|
||||
$showheader = false;
|
||||
}
|
||||
|
||||
echo "</table>\n";
|
||||
echo "<br />";
|
||||
|
||||
$currentdaytoshow = dol_time_plus_duree($currentdaytoshow, 7, 'd');
|
||||
|
||||
}
|
||||
|
||||
echo "</table>\n";
|
||||
echo '</div>';
|
||||
|
||||
if (! empty($conf->global->AGENDA_USE_EVENT_TYPE) && ! empty($conf->global->AGENDA_USE_COLOR_PER_EVENT_TYPE))
|
||||
@ -910,7 +922,7 @@ function show_day_events2($username, $day, $month, $year, $monthshown, $style, &
|
||||
$colorindexused[$user->id] = 0; // Color index for current user (user->id) is always 0
|
||||
$nextindextouse=count($colorindexused); // At first run this is 0, so first user has 0, next 1, ...
|
||||
//if ($username->id && $day==1) var_dump($eventarray);
|
||||
|
||||
|
||||
// We are in a particular day for $username, now we scan all events
|
||||
foreach ($eventarray as $daykey => $notused)
|
||||
{
|
||||
|
||||
@ -266,7 +266,7 @@ if (! empty($conf->supplier_proposal->enabled) && $user->rights->supplier_propos
|
||||
$companystatic->code_client = $obj->code_client;
|
||||
$companystatic->code_fournisseur = $obj->code_fournisseur;
|
||||
$companystatic->canvas=$obj->canvas;
|
||||
print $companystatic->getNomUrl(1,'customer',16);
|
||||
print $companystatic->getNomUrl(1,'supplier',16);
|
||||
print '</td>';
|
||||
print '<td align="right" class="nowrap">'.price($obj->total_ht).'</td></tr>';
|
||||
$i++;
|
||||
|
||||
@ -1371,7 +1371,7 @@ if ($action == 'create')
|
||||
|
||||
$soc = $objectsrc->thirdparty;
|
||||
|
||||
$cond_reglement_id = (! empty($objectsrc->cond_reglement_id)?$objectsrc->cond_reglement_id:(! empty($soc->cond_reglement_id)?$soc->cond_reglement_id:1));
|
||||
$cond_reglement_id = (! empty($objectsrc->cond_reglement_id)?$objectsrc->cond_reglement_id:(! empty($soc->cond_reglement_id)?$soc->cond_reglement_id:0)); // TODO maybe add default value option
|
||||
$mode_reglement_id = (! empty($objectsrc->mode_reglement_id)?$objectsrc->mode_reglement_id:(! empty($soc->mode_reglement_id)?$soc->mode_reglement_id:0));
|
||||
$remise_percent = (! empty($objectsrc->remise_percent)?$objectsrc->remise_percent:(! empty($soc->remise_percent)?$soc->remise_percent:0));
|
||||
$remise_absolue = (! empty($objectsrc->remise_absolue)?$objectsrc->remise_absolue:(! empty($soc->remise_absolue)?$soc->remise_absolue:0));
|
||||
@ -1458,17 +1458,13 @@ if ($action == 'create')
|
||||
|
||||
// Ligne info remises tiers
|
||||
print '<tr><td>' . $langs->trans('Discounts') . '</td><td>';
|
||||
if ($soc->remise_percent)
|
||||
print $langs->trans("CompanyHasRelativeDiscount", $soc->remise_percent);
|
||||
else
|
||||
print $langs->trans("CompanyHasNoRelativeDiscount");
|
||||
|
||||
$absolute_discount = $soc->getAvailableDiscounts();
|
||||
print '. ';
|
||||
if ($absolute_discount)
|
||||
print $langs->trans("CompanyHasAbsoluteDiscount", price($absolute_discount, 0, $langs, 1, -1, -1, $conf->currency));
|
||||
else
|
||||
print $langs->trans("CompanyHasNoAbsoluteDiscount");
|
||||
print '.';
|
||||
|
||||
$thirdparty = $soc;
|
||||
$discount_type = 0;
|
||||
$backtopage = urlencode($_SERVER["PHP_SELF"] . '?socid=' . $thirdparty->id . '&action=' . $action . '&origin=' . GETPOST('origin') . '&originid=' . GETPOST('originid'));
|
||||
include DOL_DOCUMENT_ROOT.'/core/tpl/object_discounts.tpl.php';
|
||||
print '</td></tr>';
|
||||
}
|
||||
|
||||
@ -1828,7 +1824,7 @@ if ($action == 'create')
|
||||
$morehtmlref.=$form->editfieldkey("RefCustomer", 'ref_client', $object->ref_client, $object, $user->rights->propal->creer, 'string', '', 0, 1);
|
||||
$morehtmlref.=$form->editfieldval("RefCustomer", 'ref_client', $object->ref_client, $object, $user->rights->propal->creer, 'string', '', null, null, '', 1);
|
||||
// Thirdparty
|
||||
$morehtmlref.='<br>'.$langs->trans('ThirdParty') . ' : ' . $object->thirdparty->getNomUrl(1);
|
||||
$morehtmlref.='<br>'.$langs->trans('ThirdParty') . ' : ' . $object->thirdparty->getNomUrl(1,'customer');
|
||||
if (empty($conf->global->MAIN_DISABLE_OTHER_LINK) && $object->thirdparty->id > 0) $morehtmlref.=' (<a href="'.DOL_URL_ROOT.'/comm/propal/list.php?socid='.$object->thirdparty->id.'">'.$langs->trans("OtherProposals").'</a>)';
|
||||
// Project
|
||||
if (! empty($conf->projet->enabled))
|
||||
@ -1875,31 +1871,26 @@ if ($action == 'create')
|
||||
print '<table class="border" width="100%">';
|
||||
|
||||
// Link for thirdparty discounts
|
||||
if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
|
||||
$filterabsolutediscount = "fk_facture_source IS NULL"; // If we want deposit to be substracted to payments only and not to total of final invoice
|
||||
$filtercreditnote = "fk_facture_source IS NOT NULL"; // If we want deposit to be substracted to payments only and not to total of final invoice
|
||||
} else {
|
||||
$filterabsolutediscount = "fk_facture_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS RECEIVED)%')";
|
||||
$filtercreditnote = "fk_facture_source IS NOT NULL AND (description NOT LIKE '(DEPOSIT)%' OR description LIKE '(EXCESS RECEIVED)%')";
|
||||
}
|
||||
|
||||
print '<tr><td class="titlefield">' . $langs->trans('Discounts') . '</td><td>';
|
||||
if ($soc->remise_percent)
|
||||
print $langs->trans("CompanyHasRelativeDiscount", $soc->remise_percent);
|
||||
else
|
||||
print $langs->trans("CompanyHasNoRelativeDiscount");
|
||||
print '. ';
|
||||
$absolute_discount = $soc->getAvailableDiscounts('', 'fk_facture_source IS NULL');
|
||||
$absolute_creditnote = $soc->getAvailableDiscounts('', 'fk_facture_source IS NOT NULL');
|
||||
|
||||
$absolute_discount = $soc->getAvailableDiscounts('', $filterabsolutediscount);
|
||||
$absolute_creditnote = $soc->getAvailableDiscounts('', $filtercreditnote);
|
||||
$absolute_discount = price2num($absolute_discount, 'MT');
|
||||
$absolute_creditnote = price2num($absolute_creditnote, 'MT');
|
||||
if ($absolute_discount) {
|
||||
if ($object->statut > Propal::STATUS_DRAFT) {
|
||||
print $langs->trans("CompanyHasAbsoluteDiscount", price($absolute_discount, 0, $langs, 0, 0, -1, $conf->currency));
|
||||
} else {
|
||||
// Remise dispo de type non avoir
|
||||
$filter = 'fk_facture_source IS NULL';
|
||||
print '<br>';
|
||||
$form->form_remise_dispo($_SERVER["PHP_SELF"] . '?id=' . $object->id, 0, 'remise_id', $soc->id, $absolute_discount, $filter, 0, '', 1);
|
||||
}
|
||||
}
|
||||
if ($absolute_creditnote) {
|
||||
print $langs->trans("CompanyHasCreditNote", price($absolute_creditnote, 0, $langs, 0, 0, -1, $conf->currency)) . '. ';
|
||||
}
|
||||
if (! $absolute_discount && ! $absolute_creditnote)
|
||||
print $langs->trans("CompanyHasNoAbsoluteDiscount") . '.';
|
||||
|
||||
$thirdparty = $soc;
|
||||
$discount_type = 0;
|
||||
$backtopage = urlencode($_SERVER["PHP_SELF"] . '?id=' . $object->id);
|
||||
include DOL_DOCUMENT_ROOT.'/core/tpl/object_discounts.tpl.php';
|
||||
|
||||
print '</td></tr>';
|
||||
|
||||
// Date of proposal
|
||||
|
||||
@ -164,7 +164,7 @@ if ($object->id > 0)
|
||||
$morehtmlref.=$form->editfieldkey("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', 0, 1);
|
||||
$morehtmlref.=$form->editfieldval("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', null, null, '', 1);
|
||||
// Thirdparty
|
||||
$morehtmlref.='<br>'.$langs->trans('ThirdParty') . ' : ' . $object->thirdparty->getNomUrl(1);
|
||||
$morehtmlref.='<br>'.$langs->trans('ThirdParty') . ' : ' . $object->thirdparty->getNomUrl(1,'customer');
|
||||
// Project
|
||||
if (! empty($conf->projet->enabled))
|
||||
{
|
||||
|
||||
@ -114,7 +114,7 @@ if ($object->id > 0)
|
||||
$morehtmlref.=$form->editfieldkey("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', 0, 1);
|
||||
$morehtmlref.=$form->editfieldval("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', null, null, '', 1);
|
||||
// Thirdparty
|
||||
$morehtmlref.='<br>'.$langs->trans('ThirdParty') . ' : ' . $object->thirdparty->getNomUrl(1);
|
||||
$morehtmlref.='<br>'.$langs->trans('ThirdParty') . ' : ' . $object->thirdparty->getNomUrl(1,'customer');
|
||||
// Project
|
||||
if (! empty($conf->projet->enabled))
|
||||
{
|
||||
|
||||
@ -12,6 +12,7 @@
|
||||
* Copyright (C) 2015 Jean-François Ferry <jfefe@aternatik.fr>
|
||||
* Copyright (C) 2016 Ferran Marcet <fmarcet@2byte.es>
|
||||
* Copyright (C) 2017 Charlene Benke <charlie@patas-monkey.com>
|
||||
* Copyright (C) 2018 Nicolas ZABOURI <info@inovea-conseil.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@ -214,6 +215,7 @@ if (empty($reshook))
|
||||
$objectlabel='Proposals';
|
||||
$permtoread = $user->rights->propal->lire;
|
||||
$permtodelete = $user->rights->propal->supprimer;
|
||||
$permtoclose = $user->rights->propal->cloturer;
|
||||
$uploaddir = $conf->propal->multidir_output[$conf->entity];
|
||||
include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
|
||||
}
|
||||
@ -389,7 +391,8 @@ if ($resql)
|
||||
'builddoc'=>$langs->trans("PDFMerge"),
|
||||
);
|
||||
if ($user->rights->propal->supprimer) $arrayofmassactions['predelete']=$langs->trans("Delete");
|
||||
if (in_array($massaction, array('presend','predelete'))) $arrayofmassactions=array();
|
||||
if ($user->rights->propal->cloturer) $arrayofmassactions['closed']=$langs->trans("Closed");
|
||||
if (in_array($massaction, array('presend','predelete','closed'))) $arrayofmassactions=array();
|
||||
$massactionbutton=$form->selectMassAction('', $arrayofmassactions);
|
||||
|
||||
// Lignes des champs de filtre
|
||||
|
||||
@ -56,7 +56,14 @@ if (GETPOST('action','aZ09') == 'setremise')
|
||||
{
|
||||
$object = new Societe($db);
|
||||
$object->fetch($id);
|
||||
$result=$object->set_remise_client(price2num(GETPOST("remise")),GETPOST("note"),$user);
|
||||
|
||||
$discount_type = GETPOST('discount_type', 'int');
|
||||
|
||||
if(! empty($discount_type)) {
|
||||
$result=$object->set_remise_supplier(price2num(GETPOST("remise")),GETPOST("note"),$user);
|
||||
} else {
|
||||
$result=$object->set_remise_client(price2num(GETPOST("remise")),GETPOST("note"),$user);
|
||||
}
|
||||
|
||||
if ($result > 0)
|
||||
{
|
||||
@ -100,7 +107,8 @@ if ($socid > 0)
|
||||
|
||||
$head = societe_prepare_head($object);
|
||||
|
||||
|
||||
$isCustomer = $object->client == 1 || $object->client == 3;
|
||||
$isSupplier = $object->fournisseur == 1;
|
||||
|
||||
print '<form method="POST" action="remise.php?id='.$object->id.'">';
|
||||
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
|
||||
@ -114,11 +122,33 @@ if ($socid > 0)
|
||||
print '<div class="fichecenter">';
|
||||
|
||||
print '<div class="underbanner clearboth"></div>';
|
||||
|
||||
if(! $isCustomer && ! $isSupplier) {
|
||||
print '<p class="opacitymedium">'.$langs->trans('ThirdpartyIsNeitherCustomerNorClientSoCannotHaveDiscounts').'</p>';
|
||||
|
||||
dol_fiche_end();
|
||||
|
||||
print '</form>';
|
||||
|
||||
llxFooter();
|
||||
$db->close();
|
||||
exit;
|
||||
}
|
||||
|
||||
print '<table class="border centpercent">';
|
||||
|
||||
// Discount
|
||||
print '<tr><td class="titlefield">';
|
||||
print $langs->trans("CustomerRelativeDiscount").'</td><td>'.price2num($object->remise_percent)."%</td></tr>";
|
||||
if($isCustomer) {
|
||||
// Customer discount
|
||||
print '<tr><td class="titlefield">';
|
||||
print $langs->trans("CustomerRelativeDiscount").'</td><td>'.price2num($object->remise_percent)."%</td></tr>";
|
||||
}
|
||||
|
||||
if($isSupplier) {
|
||||
// Supplier discount
|
||||
print '<tr><td class="titlefield">';
|
||||
print $langs->trans("SupplierRelativeDiscount").'</td><td>'.price2num($object->remise_supplier_percent)."%</td></tr>";
|
||||
}
|
||||
|
||||
print '</table>';
|
||||
print '<br>';
|
||||
|
||||
@ -126,8 +156,24 @@ if ($socid > 0)
|
||||
|
||||
print '<div class="underbanner clearboth"></div>';
|
||||
|
||||
if($isCustomer && ! $isSupplier) {
|
||||
print '<input type="hidden" name="discount_type" value="0" />';
|
||||
}
|
||||
|
||||
if(! $isCustomer && $isSupplier) {
|
||||
print '<input type="hidden" name="discount_type" value="1" />';
|
||||
}
|
||||
|
||||
print '<table class="border centpercent">';
|
||||
|
||||
if($isCustomer && $isSupplier) {
|
||||
// Discount type
|
||||
print '<tr><td class="titlefield fieldrequired">'.$langs->trans('DiscountType').'</td>';
|
||||
print '<td><input type="radio" name="discount_type" id="discount_type_0" selected value="0"/> <label for="discount_type_0">'.$langs->trans('Customer').'</label>';
|
||||
print ' <input type="radio" name="discount_type" id="discount_type_1" selected value="1"/> <label for="discount_type_1">'.$langs->trans('Supplier').'</label>';
|
||||
print '</td></tr>';
|
||||
}
|
||||
|
||||
// New value
|
||||
print '<tr><td class="titlefield fieldrequired">';
|
||||
print $langs->trans("NewValue").'</td><td><input type="text" size="5" name="remise" value="'.dol_escape_htmltag(GETPOST("remise")).'">%</td></tr>';
|
||||
@ -155,57 +201,128 @@ if ($socid > 0)
|
||||
|
||||
print '<br>';
|
||||
|
||||
if($isCustomer) {
|
||||
if($isSupplier) {
|
||||
print '<div class="fichecenter">';
|
||||
print '<div class="fichehalfleft">';
|
||||
print load_fiche_titre($langs->trans("CustomerDiscounts"), '', '');
|
||||
}
|
||||
|
||||
/*
|
||||
* List log of all percent discounts
|
||||
*/
|
||||
$sql = "SELECT rc.rowid, rc.remise_client as remise_percent, rc.note, rc.datec as dc,";
|
||||
$sql.= " u.login, u.rowid as user_id";
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX."societe_remise as rc, ".MAIN_DB_PREFIX."user as u";
|
||||
$sql.= " WHERE rc.fk_soc = " . $object->id;
|
||||
$sql.= " AND rc.entity = " . $conf->entity;
|
||||
$sql.= " AND u.rowid = rc.fk_user_author";
|
||||
$sql.= " ORDER BY rc.datec DESC";
|
||||
|
||||
$resql=$db->query($sql);
|
||||
if ($resql)
|
||||
{
|
||||
print '<table class="noborder" width="100%">';
|
||||
$tag = !$tag;
|
||||
print '<tr class="liste_titre">';
|
||||
print '<td width="160">'.$langs->trans("Date").'</td>';
|
||||
print '<td width="160" align="center">'.$langs->trans("CustomerRelativeDiscountShort").'</td>';
|
||||
print '<td align="left">'.$langs->trans("NoteReason").'</td>';
|
||||
print '<td align="center">'.$langs->trans("User").'</td>';
|
||||
print '</tr>';
|
||||
$num = $db->num_rows($resql);
|
||||
if ($num > 0)
|
||||
{
|
||||
$i = 0;
|
||||
while ($i < $num)
|
||||
{
|
||||
$obj = $db->fetch_object($resql);
|
||||
print '<tr class="oddeven">';
|
||||
print '<td>'.dol_print_date($db->jdate($obj->dc),"dayhour").'</td>';
|
||||
print '<td align="center">'.price2num($obj->remise_percent).'%</td>';
|
||||
print '<td align="left">'.$obj->note.'</td>';
|
||||
print '<td align="center"><a href="'.DOL_URL_ROOT.'/user/card.php?id='.$obj->user_id.'">'.img_object($langs->trans("ShowUser"),'user').' '.$obj->login.'</a></td>';
|
||||
print '</tr>';
|
||||
$i++;
|
||||
}
|
||||
/*
|
||||
* List log of all customer percent discounts
|
||||
*/
|
||||
$sql = "SELECT rc.rowid, rc.remise_client as remise_percent, rc.note, rc.datec as dc,";
|
||||
$sql.= " u.login, u.rowid as user_id";
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX."societe_remise as rc, ".MAIN_DB_PREFIX."user as u";
|
||||
$sql.= " WHERE rc.fk_soc = " . $object->id;
|
||||
$sql.= " AND rc.entity = " . $conf->entity;
|
||||
$sql.= " AND u.rowid = rc.fk_user_author";
|
||||
$sql.= " ORDER BY rc.datec DESC";
|
||||
|
||||
$resql=$db->query($sql);
|
||||
if ($resql)
|
||||
{
|
||||
print '<table class="noborder" width="100%">';
|
||||
$tag = !$tag;
|
||||
print '<tr class="liste_titre">';
|
||||
print '<td width="160">'.$langs->trans("Date").'</td>';
|
||||
print '<td width="160" align="center">'.$langs->trans("CustomerRelativeDiscountShort").'</td>';
|
||||
print '<td align="left">'.$langs->trans("NoteReason").'</td>';
|
||||
print '<td align="center">'.$langs->trans("User").'</td>';
|
||||
print '</tr>';
|
||||
$num = $db->num_rows($resql);
|
||||
if ($num > 0)
|
||||
{
|
||||
$i = 0;
|
||||
while ($i < $num)
|
||||
{
|
||||
$obj = $db->fetch_object($resql);
|
||||
print '<tr class="oddeven">';
|
||||
print '<td>'.dol_print_date($db->jdate($obj->dc),"dayhour").'</td>';
|
||||
print '<td align="center">'.price2num($obj->remise_percent).'%</td>';
|
||||
print '<td align="left">'.$obj->note.'</td>';
|
||||
print '<td align="center"><a href="'.DOL_URL_ROOT.'/user/card.php?id='.$obj->user_id.'">'.img_object($langs->trans("ShowUser"),'user').' '.$obj->login.'</a></td>';
|
||||
print '</tr>';
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
print '<tr><td colspan="8" class="opacitymedium">'.$langs->trans("None").'</td></tr>';
|
||||
}
|
||||
$db->free($resql);
|
||||
print "</table>";
|
||||
}
|
||||
else
|
||||
{
|
||||
print '<tr><td colspan="8" class="opacitymedium">'.$langs->trans("None").'</td></tr>';
|
||||
dol_print_error($db);
|
||||
}
|
||||
$db->free($resql);
|
||||
print "</table>";
|
||||
}
|
||||
else
|
||||
{
|
||||
dol_print_error($db);
|
||||
}
|
||||
|
||||
if($isSupplier) {
|
||||
if($isCustomer) {
|
||||
print '</div>'; // class="fichehalfleft"
|
||||
print '<div class="fichehalfright">';
|
||||
print '<div class="ficheaddleft">';
|
||||
print load_fiche_titre($langs->trans("SupplierDiscounts"), '', '');
|
||||
}
|
||||
|
||||
/*
|
||||
* List log of all supplier percent discounts
|
||||
*/
|
||||
$sql = "SELECT rc.rowid, rc.remise_supplier as remise_percent, rc.note, rc.datec as dc,";
|
||||
$sql.= " u.login, u.rowid as user_id";
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX."societe_remise_supplier as rc, ".MAIN_DB_PREFIX."user as u";
|
||||
$sql.= " WHERE rc.fk_soc = " . $object->id;
|
||||
$sql.= " AND rc.entity = " . $conf->entity;
|
||||
$sql.= " AND u.rowid = rc.fk_user_author";
|
||||
$sql.= " ORDER BY rc.datec DESC";
|
||||
|
||||
$resql=$db->query($sql);
|
||||
if ($resql)
|
||||
{
|
||||
print '<table class="noborder" width="100%">';
|
||||
$tag = !$tag;
|
||||
print '<tr class="liste_titre">';
|
||||
print '<td width="160">'.$langs->trans("Date").'</td>';
|
||||
print '<td width="160" align="center">'.$langs->trans("CustomerRelativeDiscountShort").'</td>';
|
||||
print '<td align="left">'.$langs->trans("NoteReason").'</td>';
|
||||
print '<td align="center">'.$langs->trans("User").'</td>';
|
||||
print '</tr>';
|
||||
$num = $db->num_rows($resql);
|
||||
if ($num > 0)
|
||||
{
|
||||
$i = 0;
|
||||
while ($i < $num)
|
||||
{
|
||||
$obj = $db->fetch_object($resql);
|
||||
print '<tr class="oddeven">';
|
||||
print '<td>'.dol_print_date($db->jdate($obj->dc),"dayhour").'</td>';
|
||||
print '<td align="center">'.price2num($obj->remise_percent).'%</td>';
|
||||
print '<td align="left">'.$obj->note.'</td>';
|
||||
print '<td align="center"><a href="'.DOL_URL_ROOT.'/user/card.php?id='.$obj->user_id.'">'.img_object($langs->trans("ShowUser"),'user').' '.$obj->login.'</a></td>';
|
||||
print '</tr>';
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
print '<tr><td colspan="8" class="opacitymedium">'.$langs->trans("None").'</td></tr>';
|
||||
}
|
||||
$db->free($resql);
|
||||
print "</table>";
|
||||
}
|
||||
else
|
||||
{
|
||||
dol_print_error($db);
|
||||
}
|
||||
|
||||
if($isCustomer) {
|
||||
print '</div>'; // class="ficheaddleft"
|
||||
print '</div>'; // class="fichehalfright"
|
||||
print '</div>'; // class="fichecenter"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
llxFooter();
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@ -1450,7 +1450,7 @@ if ($action == 'create' && $user->rights->commande->creer)
|
||||
$ref_client = (! empty($objectsrc->ref_client) ? $objectsrc->ref_client : '');
|
||||
|
||||
$soc = $objectsrc->thirdparty;
|
||||
$cond_reglement_id = (!empty($objectsrc->cond_reglement_id)?$objectsrc->cond_reglement_id:(!empty($soc->cond_reglement_id)?$soc->cond_reglement_id:1));
|
||||
$cond_reglement_id = (!empty($objectsrc->cond_reglement_id)?$objectsrc->cond_reglement_id:(!empty($soc->cond_reglement_id)?$soc->cond_reglement_id:0)); // TODO maybe add default value option
|
||||
$mode_reglement_id = (!empty($objectsrc->mode_reglement_id)?$objectsrc->mode_reglement_id:(!empty($soc->mode_reglement_id)?$soc->mode_reglement_id:0));
|
||||
$fk_account = (! empty($objectsrc->fk_account)?$objectsrc->fk_account:(! empty($soc->fk_account)?$soc->fk_account:0));
|
||||
$availability_id = (!empty($objectsrc->availability_id)?$objectsrc->availability_id:(!empty($soc->availability_id)?$soc->availability_id:0));
|
||||
@ -1558,17 +1558,14 @@ if ($action == 'create' && $user->rights->commande->creer)
|
||||
|
||||
// Ligne info remises tiers
|
||||
print '<tr><td>' . $langs->trans('Discounts') . '</td><td>';
|
||||
if ($soc->remise_percent)
|
||||
print $langs->trans("CompanyHasRelativeDiscount", $soc->remise_percent);
|
||||
else
|
||||
print $langs->trans("CompanyHasNoRelativeDiscount");
|
||||
print '. ';
|
||||
|
||||
$absolute_discount = $soc->getAvailableDiscounts();
|
||||
if ($absolute_discount)
|
||||
print $langs->trans("CompanyHasAbsoluteDiscount", price($absolute_discount), $langs->trans("Currency" . $conf->currency));
|
||||
else
|
||||
print $langs->trans("CompanyHasNoAbsoluteDiscount");
|
||||
print '.';
|
||||
|
||||
$thirdparty = $soc;
|
||||
$discount_type = 0;
|
||||
$backtopage = urlencode($_SERVER["PHP_SELF"] . '?socid=' . $thirdparty->id . '&action=' . $action . '&origin=' . GETPOST('origin') . '&originid=' . GETPOST('originid'));
|
||||
include DOL_DOCUMENT_ROOT.'/core/tpl/object_discounts.tpl.php';
|
||||
|
||||
print '</td></tr>';
|
||||
}
|
||||
// Date
|
||||
@ -2040,12 +2037,11 @@ if ($action == 'create' && $user->rights->commande->creer)
|
||||
|
||||
// Relative and absolute discounts
|
||||
if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
|
||||
$filterabsolutediscount = "fk_facture_source IS NULL"; // If we want deposit to be substracted to payments only and not to total of final
|
||||
// invoice
|
||||
$filterabsolutediscount = "fk_facture_source IS NULL"; // If we want deposit to be substracted to payments only and not to total of final invoice
|
||||
$filtercreditnote = "fk_facture_source IS NOT NULL"; // If we want deposit to be substracted to payments only and not to total of final invoice
|
||||
} else {
|
||||
$filterabsolutediscount = "fk_facture_source IS NULL OR (fk_facture_source IS NOT NULL AND description LIKE '(DEPOSIT)%')";
|
||||
$filtercreditnote = "fk_facture_source IS NOT NULL AND description NOT LIKE '(DEPOSIT)%'";
|
||||
$filterabsolutediscount = "fk_facture_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS RECEIVED)%')";
|
||||
$filtercreditnote = "fk_facture_source IS NOT NULL AND (description NOT LIKE '(DEPOSIT)%' OR description LIKE '(EXCESS RECEIVED)%')";
|
||||
}
|
||||
|
||||
$addrelativediscount = '<a href="' . DOL_URL_ROOT . '/comm/remise.php?id=' . $soc->id . '&backtopage=' . urlencode($_SERVER["PHP_SELF"]) . '?facid=' . $object->id . '">' . $langs->trans("EditRelativeDiscounts") . '</a>';
|
||||
@ -2053,29 +2049,17 @@ if ($action == 'create' && $user->rights->commande->creer)
|
||||
$addcreditnote = '<a href="' . DOL_URL_ROOT . '/compta/facture/card.php?action=create&socid=' . $soc->id . '&type=2&backtopage=' . urlencode($_SERVER["PHP_SELF"]) . '?facid=' . $object->id . '">' . $langs->trans("AddCreditNote") . '</a>';
|
||||
|
||||
print '<tr><td class="titlefield">' . $langs->trans('Discounts') . '</td><td>';
|
||||
if ($soc->remise_percent)
|
||||
print $langs->trans("CompanyHasRelativeDiscount", $soc->remise_percent);
|
||||
else
|
||||
print $langs->trans("CompanyHasNoRelativeDiscount");
|
||||
print '. ';
|
||||
$absolute_discount = $soc->getAvailableDiscounts('', 'fk_facture_source IS NULL');
|
||||
$absolute_creditnote = $soc->getAvailableDiscounts('', 'fk_facture_source IS NOT NULL');
|
||||
|
||||
$absolute_discount = $soc->getAvailableDiscounts('', $filterabsolutediscount);
|
||||
$absolute_creditnote = $soc->getAvailableDiscounts('', $filtercreditnote);
|
||||
$absolute_discount = price2num($absolute_discount, 'MT');
|
||||
$absolute_creditnote = price2num($absolute_creditnote, 'MT');
|
||||
if ($absolute_discount) {
|
||||
if ($object->statut > Commande::STATUS_DRAFT) {
|
||||
print $langs->trans("CompanyHasAbsoluteDiscount", price($absolute_discount), $langs->transnoentities("Currency" . $conf->currency));
|
||||
} else {
|
||||
// Remise dispo de type remise fixe (not credit note)
|
||||
print '<br>';
|
||||
$form->form_remise_dispo($_SERVER["PHP_SELF"] . '?id=' . $object->id, 0, 'remise_id', $soc->id, $absolute_discount, $filterabsolutediscount, 0, '', 1);
|
||||
}
|
||||
}
|
||||
if ($absolute_creditnote) {
|
||||
print $langs->trans("CompanyHasCreditNote", price($absolute_creditnote), $langs->transnoentities("Currency" . $conf->currency)) . '. ';
|
||||
}
|
||||
if (! $absolute_discount && ! $absolute_creditnote)
|
||||
print $langs->trans("CompanyHasNoAbsoluteDiscount") . '.';
|
||||
|
||||
$thirdparty = $soc;
|
||||
$discount_type = 0;
|
||||
$backtopage = urlencode($_SERVER["PHP_SELF"] . '?id=' . $object->id);
|
||||
include DOL_DOCUMENT_ROOT.'/core/tpl/object_discounts.tpl.php';
|
||||
|
||||
print '</td></tr>';
|
||||
|
||||
// Date
|
||||
|
||||
@ -509,6 +509,8 @@ class Account extends CommonObject
|
||||
{
|
||||
global $langs,$conf, $hookmanager;
|
||||
|
||||
$error=0;
|
||||
|
||||
// Clean parameters
|
||||
if (! $this->min_allowed) $this->min_allowed=0;
|
||||
if (! $this->min_desired) $this->min_desired=0;
|
||||
@ -668,7 +670,7 @@ class Account extends CommonObject
|
||||
* @param int $notrigger 1=Disable triggers
|
||||
* @return int <0 if KO, >0 if OK
|
||||
*/
|
||||
function update(User $user = null, $notrigger = 0)
|
||||
function update(User $user, $notrigger = 0)
|
||||
{
|
||||
global $langs,$conf, $hookmanager;
|
||||
|
||||
@ -1135,6 +1137,8 @@ class Account extends CommonObject
|
||||
*/
|
||||
function solde($option=0)
|
||||
{
|
||||
$solde=0;
|
||||
|
||||
$sql = "SELECT sum(amount) as amount";
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX."bank";
|
||||
$sql.= " WHERE fk_account = ".$this->id;
|
||||
@ -1149,8 +1153,13 @@ class Account extends CommonObject
|
||||
$solde = $obj->amount;
|
||||
}
|
||||
$this->db->free($resql);
|
||||
return $solde;
|
||||
} else {
|
||||
$this->errors[]=$this->db->lasterror;
|
||||
return -1;
|
||||
}
|
||||
|
||||
return $solde;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1593,7 +1602,7 @@ class Account extends CommonObject
|
||||
$this->code_banque = '123';
|
||||
$this->code_guichet = '456';
|
||||
$this->number = 'ABC12345';
|
||||
$this->cle_rib = 50;
|
||||
$this->cle_rib = '50';
|
||||
$this->bic = 'AA12';
|
||||
$this->iban = 'FR999999999';
|
||||
$this->domiciliation = 'My bank address';
|
||||
@ -1904,7 +1913,7 @@ class AccountLine extends CommonObject
|
||||
*/
|
||||
function update_conciliation(User $user, $cat)
|
||||
{
|
||||
global $conf;
|
||||
global $conf,$langs;
|
||||
|
||||
$this->db->begin();
|
||||
|
||||
@ -2132,9 +2141,10 @@ class AccountLine extends CommonObject
|
||||
* @param int $withpicto 0=No picto, 1=Include picto into link, 2=Only picto
|
||||
* @param int $maxlen Longueur max libelle
|
||||
* @param string $option Option ('showall')
|
||||
* @param int $notooltip 1=Disable tooltip
|
||||
* @return string Chaine avec URL
|
||||
*/
|
||||
function getNomUrl($withpicto=0,$maxlen=0,$option='')
|
||||
function getNomUrl($withpicto=0,$maxlen=0,$option='',$notooltip=0)
|
||||
{
|
||||
global $langs;
|
||||
|
||||
|
||||
@ -2699,19 +2699,12 @@ if ($action == 'create')
|
||||
{
|
||||
// Discounts for third party
|
||||
print '<tr><td>' . $langs->trans('Discounts') . '</td><td colspan="2">';
|
||||
if ($soc->remise_percent)
|
||||
print $langs->trans("CompanyHasRelativeDiscount", '<a href="' . DOL_URL_ROOT . '/comm/remise.php?id=' . $soc->id . '&backtopage=' . urlencode($_SERVER["PHP_SELF"] . '?socid=' . $soc->id . '&action=' . $action . '&origin=' . GETPOST('origin') . '&originid=' . GETPOST('originid')) . '">' . $soc->remise_percent . '</a>');
|
||||
else
|
||||
print $langs->trans("CompanyHasNoRelativeDiscount");
|
||||
print ' <a href="' . DOL_URL_ROOT . '/comm/remise.php?id=' . $soc->id . '&backtopage=' . urlencode($_SERVER["PHP_SELF"] . '?socid=' . $soc->id . '&action=' . $action . '&origin=' . GETPOST('origin') . '&originid=' . GETPOST('originid')) . '">(' . $langs->trans("EditRelativeDiscount") . ')</a>';
|
||||
print '. ';
|
||||
print '<br>';
|
||||
if ($absolute_discount)
|
||||
print $langs->trans("CompanyHasAbsoluteDiscount", '<a href="' . DOL_URL_ROOT . '/comm/remx.php?id=' . $soc->id . '&backtopage=' . urlencode($_SERVER["PHP_SELF"] . '?socid=' . $soc->id . '&action=' . $action . '&origin=' . GETPOST('origin') . '&originid=' . GETPOST('originid')) . '">' . price($absolute_discount) . '</a>', $langs->trans("Currency" . $conf->currency));
|
||||
else
|
||||
print $langs->trans("CompanyHasNoAbsoluteDiscount");
|
||||
print ' <a href="' . DOL_URL_ROOT . '/comm/remx.php?id=' . $soc->id . '&backtopage=' . urlencode($_SERVER["PHP_SELF"] . '?socid=' . $soc->id . '&action=' . $action . '&origin=' . GETPOST('origin') . '&originid=' . GETPOST('originid')) . '">(' . $langs->trans("EditGlobalDiscounts") . ')</a>';
|
||||
print '.';
|
||||
|
||||
$thirdparty = $soc;
|
||||
$discount_type = 0;
|
||||
$backtopage = urlencode($_SERVER["PHP_SELF"] . '?socid=' . $thirdparty->id . '&action=' . $action . '&origin=' . GETPOST('origin') . '&originid=' . GETPOST('originid'));
|
||||
include DOL_DOCUMENT_ROOT.'/core/tpl/object_discounts.tpl.php';
|
||||
|
||||
print '</td></tr>';
|
||||
}
|
||||
|
||||
@ -3000,7 +2993,7 @@ else if ($id > 0 || ! empty($ref))
|
||||
$filterabsolutediscount = "fk_facture_source IS NULL"; // If we want deposit to be substracted to payments only and not to total of final invoice
|
||||
$filtercreditnote = "fk_facture_source IS NOT NULL"; // If we want deposit to be substracted to payments only and not to total of final invoice
|
||||
} else {
|
||||
$filterabsolutediscount = "fk_facture_source IS NULL OR (fk_facture_source IS NOT NULL AND (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS RECEIVED)%'))";
|
||||
$filterabsolutediscount = "fk_facture_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS RECEIVED)%')";
|
||||
$filtercreditnote = "fk_facture_source IS NOT NULL AND (description NOT LIKE '(DEPOSIT)%' OR description LIKE '(EXCESS RECEIVED)%')";
|
||||
}
|
||||
|
||||
@ -3272,7 +3265,7 @@ else if ($id > 0 || ! empty($ref))
|
||||
$morehtmlref.=$form->editfieldkey("RefCustomer", 'ref_client', $object->ref_client, $object, $user->rights->facture->creer, 'string', '', 0, 1);
|
||||
$morehtmlref.=$form->editfieldval("RefCustomer", 'ref_client', $object->ref_client, $object, $user->rights->facture->creer, 'string', '', null, null, '', 1);
|
||||
// Thirdparty
|
||||
$morehtmlref.='<br>'.$langs->trans('ThirdParty') . ' : ' . $object->thirdparty->getNomUrl(1);
|
||||
$morehtmlref.='<br>'.$langs->trans('ThirdParty') . ' : ' . $object->thirdparty->getNomUrl(1,'customer');
|
||||
if (empty($conf->global->MAIN_DISABLE_OTHER_LINK) && $object->thirdparty->id > 0) $morehtmlref.=' (<a href="'.DOL_URL_ROOT.'/compta/facture/list.php?socid='.$object->thirdparty->id.'">'.$langs->trans("OtherBills").'</a>)';
|
||||
// Project
|
||||
if (! empty($conf->projet->enabled))
|
||||
@ -3363,84 +3356,14 @@ else if ($id > 0 || ! empty($ref))
|
||||
print '</td></tr>';
|
||||
|
||||
// Relative and absolute discounts
|
||||
$addrelativediscount = '<a href="' . DOL_URL_ROOT . '/comm/remise.php?id=' . $soc->id . '&backtopage=' . urlencode($_SERVER["PHP_SELF"]) . '?facid=' . $object->id . '">' . $langs->trans("EditRelativeDiscounts") . '</a>';
|
||||
$addabsolutediscount = '<a href="' . DOL_URL_ROOT . '/comm/remx.php?id=' . $soc->id . '&backtopage=' . urlencode($_SERVER["PHP_SELF"]) . '?facid=' . $object->id . '">' . $langs->trans("EditGlobalDiscounts") . '</a>';
|
||||
$addcreditnote = '<a href="' . DOL_URL_ROOT . '/compta/facture/card.php?action=create&socid=' . $soc->id . '&type=2&backtopage=' . urlencode($_SERVER["PHP_SELF"]) . '?facid=' . $object->id . '">' . $langs->trans("AddCreditNote") . '</a>';
|
||||
$viewabsolutediscount = '<a href="' . DOL_URL_ROOT . '/comm/remx.php?id=' . $soc->id . '&backtopage=' . urlencode($_SERVER["PHP_SELF"]) . '?facid=' . $object->id . '">' . $langs->trans("ViewAvailableGlobalDiscounts") . '</a>';
|
||||
|
||||
print '<!-- Discounts --><tr><td>' . $langs->trans('Discounts');
|
||||
print '</td><td>';
|
||||
if ($soc->remise_percent)
|
||||
print $langs->trans("CompanyHasRelativeDiscount", $soc->remise_percent);
|
||||
else
|
||||
print $langs->trans("CompanyHasNoRelativeDiscount");
|
||||
// print ' ('.$addrelativediscount.')';
|
||||
|
||||
// Is there is commercial discount or down payment available ?
|
||||
if ($absolute_discount > 0) {
|
||||
print '. ';
|
||||
if ($object->statut > 0 || $object->type == Facture::TYPE_CREDIT_NOTE || $object->type == Facture::TYPE_DEPOSIT) {
|
||||
if ($object->statut == 0) {
|
||||
print $langs->trans("CompanyHasAbsoluteDiscount", price($absolute_discount), $langs->transnoentities("Currency" . $conf->currency));
|
||||
print '. ';
|
||||
} else {
|
||||
if ($object->statut < 1 || $object->type == Facture::TYPE_CREDIT_NOTE || $object->type == Facture::TYPE_DEPOSIT) {
|
||||
$text = $langs->trans("CompanyHasAbsoluteDiscount", price($absolute_discount), $langs->transnoentities("Currency" . $conf->currency));
|
||||
print '<br>' . $text . '.<br>';
|
||||
} else {
|
||||
$text = $langs->trans("CompanyHasAbsoluteDiscount", price($absolute_discount), $langs->transnoentities("Currency" . $conf->currency));
|
||||
$text2 = $langs->trans("AbsoluteDiscountUse");
|
||||
print $form->textwithpicto($text, $text2);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Discount available of type fixed amount (not credit note)
|
||||
print '<br>';
|
||||
$form->form_remise_dispo($_SERVER["PHP_SELF"] . '?facid=' . $object->id, GETPOST('discountid'), 'remise_id', $soc->id, $absolute_discount, $filterabsolutediscount, $resteapayer, ' (' . $addabsolutediscount . ')');
|
||||
}
|
||||
} else {
|
||||
if ($absolute_creditnote > 0) // If not, link will be added later
|
||||
{
|
||||
if ($object->statut == Facture::STATUS_DRAFT && $object->type != Facture::TYPE_CREDIT_NOTE && $object->type != Facture::TYPE_DEPOSIT)
|
||||
print ' (' . $addabsolutediscount . ')<br>';
|
||||
else
|
||||
print '. ';
|
||||
} else
|
||||
print '. ';
|
||||
}
|
||||
// Is there credit notes availables ?
|
||||
if ($absolute_creditnote > 0)
|
||||
{
|
||||
// If validated, we show link "add credit note to payment"
|
||||
if ($object->statut != Facture::STATUS_VALIDATED || $object->type == Facture::TYPE_CREDIT_NOTE) {
|
||||
if ($object->statut == 0 && $object->type != Facture::TYPE_DEPOSIT) {
|
||||
$text = $langs->trans("CompanyHasCreditNote", price($absolute_creditnote), $langs->transnoentities("Currency" . $conf->currency));
|
||||
print $form->textwithpicto($text, $langs->trans("CreditNoteDepositUse"));
|
||||
} else {
|
||||
print $langs->trans("CompanyHasCreditNote", price($absolute_creditnote), $langs->transnoentities("Currency" . $conf->currency)) . '.';
|
||||
}
|
||||
} else { // We can add a credit note on a down payment or standard invoice or situation invoice
|
||||
// There is credit notes discounts available
|
||||
if (! $absolute_discount) print '<br>';
|
||||
// $form->form_remise_dispo($_SERVER["PHP_SELF"].'?facid='.$object->id, 0, 'remise_id_for_payment', $soc->id, $absolute_creditnote, $filtercreditnote, $resteapayer);
|
||||
$more=' ('.$addcreditnote. (($addcreditnote && $viewabsolutediscount) ? ' - ' : '') . $viewabsolutediscount . ')';
|
||||
$form->form_remise_dispo($_SERVER["PHP_SELF"] . '?facid=' . $object->id, 0, 'remise_id_for_payment', $soc->id, $absolute_creditnote, $filtercreditnote, 0, $more); // We allow credit note even if amount is higher
|
||||
}
|
||||
}
|
||||
if (! $absolute_discount && ! $absolute_creditnote) {
|
||||
print $langs->trans("CompanyHasNoAbsoluteDiscount");
|
||||
if ($object->statut == Facture::STATUS_DRAFT && $object->type != Facture::TYPE_CREDIT_NOTE && $object->type != Facture::TYPE_DEPOSIT)
|
||||
print ' (' . $addabsolutediscount . ')<br>';
|
||||
else
|
||||
print '. ';
|
||||
}
|
||||
// if ($object->statut == 0 && $object->type != 2 && $object->type != 3)
|
||||
// {
|
||||
// if (! $absolute_discount && ! $absolute_creditnote) print '<br>';
|
||||
// print ' - ';
|
||||
// print $addabsolutediscount;
|
||||
// print ' - '.$addcreditnote; // We disbale link to credit note
|
||||
// }
|
||||
print '</td><td>';
|
||||
$thirdparty = $soc;
|
||||
$discount_type = 0;
|
||||
$backtopage = urlencode($_SERVER["PHP_SELF"] . '?facid=' . $object->id);
|
||||
include DOL_DOCUMENT_ROOT.'/core/tpl/object_discounts.tpl.php';
|
||||
|
||||
print '</td></tr>';
|
||||
|
||||
// Date invoice
|
||||
|
||||
@ -140,7 +140,7 @@ class Facture extends CommonInvoice
|
||||
public $situation_counter;
|
||||
|
||||
/**
|
||||
* @var bool Final situation flag
|
||||
* @var int Final situation flag
|
||||
*/
|
||||
public $situation_final;
|
||||
|
||||
@ -303,13 +303,13 @@ class Facture extends CommonInvoice
|
||||
$this->entity = $_facrec->entity; // Invoice created in same entity than template
|
||||
|
||||
// Fields coming from GUI (priority on template). TODO Value of template should be used as default value on GUI so we can use here always value from GUI
|
||||
$this->fk_project = GETPOST('projectid','int') > 0 ? GETPOST('projectid','int') : $_facrec->fk_project;
|
||||
$this->fk_project = (int)GETPOST('projectid','int') > 0 ? (int)GETPOST('projectid','int') : $_facrec->fk_project;
|
||||
$this->note_public = GETPOST('note_public','none') ? GETPOST('note_public','none') : $_facrec->note_public;
|
||||
$this->note_private = GETPOST('note_private','none') ? GETPOST('note_private','none') : $_facrec->note_private;
|
||||
$this->modelpdf = GETPOST('model') ? GETPOST('model') : $_facrec->modelpdf;
|
||||
$this->cond_reglement_id = GETPOST('cond_reglement_id') > 0 ? GETPOST('cond_reglement_id') : $_facrec->cond_reglement_id;
|
||||
$this->mode_reglement_id = GETPOST('mode_reglement_id') > 0 ? GETPOST('mode_reglement_id') : $_facrec->mode_reglement_id;
|
||||
$this->fk_account = GETPOST('fk_account') > 0 ? GETPOST('fk_account') : $_facrec->fk_account;
|
||||
$this->cond_reglement_id = (int)GETPOST('cond_reglement_id') > 0 ? (int)GETPOST('cond_reglement_id') : $_facrec->cond_reglement_id;
|
||||
$this->mode_reglement_id = (int)GETPOST('mode_reglement_id') > 0 ? (int)GETPOST('mode_reglement_id') : $_facrec->mode_reglement_id;
|
||||
$this->fk_account = (int)GETPOST('fk_account') > 0 ? (int)GETPOST('fk_account') : $_facrec->fk_account;
|
||||
|
||||
// Set here to have this defined for substitution into notes, should be recalculated after adding lines to get same result
|
||||
$this->total_ht = $_facrec->total_ht;
|
||||
@ -860,7 +860,7 @@ class Facture extends CommonInvoice
|
||||
}
|
||||
elseif ($this->type == self::TYPE_SITUATION && !empty($conf->global->INVOICE_USE_SITUATION))
|
||||
{
|
||||
$this->fetchObjectLinked('', '', $object->id, 'facture');
|
||||
$this->fetchObjectLinked('', '', $facture->id, 'facture');
|
||||
|
||||
foreach ($this->linkedObjectsIds as $typeObject => $Tfk_object)
|
||||
{
|
||||
@ -1519,7 +1519,7 @@ class Facture extends CommonInvoice
|
||||
* @param int $notrigger 0=launch triggers after, 1=disable triggers
|
||||
* @return int <0 if KO, >0 if OK
|
||||
*/
|
||||
function update($user=null, $notrigger=0)
|
||||
function update(User $user, $notrigger=0)
|
||||
{
|
||||
$error=0;
|
||||
|
||||
@ -1535,17 +1535,6 @@ class Facture extends CommonInvoice
|
||||
if (isset($this->note_public)) $this->note_public=trim($this->note_public);
|
||||
if (isset($this->modelpdf)) $this->modelpdf=trim($this->modelpdf);
|
||||
if (isset($this->import_key)) $this->import_key=trim($this->import_key);
|
||||
if (empty($this->situation_cycle_ref)) {
|
||||
$this->situation_cycle_ref = 'null';
|
||||
}
|
||||
|
||||
if (empty($this->situation_counter)) {
|
||||
$this->situation_counter = 'null';
|
||||
}
|
||||
|
||||
if (empty($this->situation_final)) {
|
||||
$this->situation_final = '0';
|
||||
}
|
||||
|
||||
// Check parameters
|
||||
// Put here code to add control on parameters values
|
||||
@ -1585,9 +1574,9 @@ class Facture extends CommonInvoice
|
||||
$sql.= " note_public=".(isset($this->note_public)?"'".$this->db->escape($this->note_public)."'":"null").",";
|
||||
$sql.= " model_pdf=".(isset($this->modelpdf)?"'".$this->db->escape($this->modelpdf)."'":"null").",";
|
||||
$sql.= " import_key=".(isset($this->import_key)?"'".$this->db->escape($this->import_key)."'":"null");
|
||||
$sql.= ", situation_cycle_ref=".$this->situation_cycle_ref;
|
||||
$sql.= ", situation_counter=".$this->situation_counter;
|
||||
$sql.= ", situation_final=".$this->situation_final;
|
||||
$sql.= ", situation_cycle_ref=".(empty($this->situation_cycle_ref)?"null":$this->situation_cycle_ref);
|
||||
$sql.= ", situation_counter=".(empty($this->situation_counter)?"null":$this->situation_counter);
|
||||
$sql.= ", situation_final=".(empty($this->situation_counter)?"0":$this->situation_counter);
|
||||
|
||||
$sql.= " WHERE rowid=".$this->id;
|
||||
|
||||
@ -1810,9 +1799,9 @@ class Facture extends CommonInvoice
|
||||
dol_syslog(get_class($this)."::delete rowid=".$rowid.", ref=".$this->ref.", thirdparty=".$this->thirdparty->name, LOG_DEBUG);
|
||||
|
||||
// Test to avoid invoice deletion (allowed if draft)
|
||||
$test = $this->is_erasable();
|
||||
$result = $this->is_erasable();
|
||||
|
||||
if ($test <= 0) return 0;
|
||||
if ($result <= 0) return 0;
|
||||
|
||||
$error=0;
|
||||
|
||||
@ -2556,7 +2545,7 @@ class Facture extends CommonInvoice
|
||||
* @param double $pu_ht_devise Unit price in currency
|
||||
* @return int <0 if KO, Id of line if OK
|
||||
*/
|
||||
function addline($desc, $pu_ht, $qty, $txtva, $txlocaltax1=0, $txlocaltax2=0, $fk_product=0, $remise_percent=0, $date_start='', $date_end='', $ventil=0, $info_bits=0, $fk_remise_except='', $price_base_type='HT', $pu_ttc=0, $type=self::TYPE_STANDARD, $rang=-1, $special_code=0, $origin='', $origin_id=0, $fk_parent_line=0, $fk_fournprice=null, $pa_ht=0, $label='', $array_options=0, $situation_percent=100, $fk_prev_id='', $fk_unit = null, $pu_ht_devise = 0)
|
||||
function addline($desc, $pu_ht, $qty, $txtva, $txlocaltax1=0, $txlocaltax2=0, $fk_product=0, $remise_percent=0, $date_start='', $date_end='', $ventil=0, $info_bits=0, $fk_remise_except='', $price_base_type='HT', $pu_ttc=0, $type=self::TYPE_STANDARD, $rang=-1, $special_code=0, $origin='', $origin_id=0, $fk_parent_line=0, $fk_fournprice=null, $pa_ht=0, $label='', $array_options=0, $situation_percent=100, $fk_prev_id=0, $fk_unit = null, $pu_ht_devise = 0)
|
||||
{
|
||||
// Deprecation warning
|
||||
if ($label) {
|
||||
@ -3061,7 +3050,7 @@ class Facture extends CommonInvoice
|
||||
|
||||
// For triggers
|
||||
$result = $line->fetch($rowid);
|
||||
if (! ($result > 0)) dol_print_error($db, $line->error, $line->errors);
|
||||
if (! ($result > 0)) dol_print_error($this->db, $line->error, $line->errors);
|
||||
|
||||
if ($line->delete($user) > 0)
|
||||
{
|
||||
@ -4379,7 +4368,7 @@ class FactureLigne extends CommonInvoiceLine
|
||||
if (empty($this->subprice)) $this->subprice=0;
|
||||
if (empty($this->special_code)) $this->special_code=0;
|
||||
if (empty($this->fk_parent_line)) $this->fk_parent_line=0;
|
||||
if (empty($this->fk_prev_id)) $this->fk_prev_id = 'null';
|
||||
if (empty($this->fk_prev_id)) $this->fk_prev_id = 0;
|
||||
if (! isset($this->situation_percent) || $this->situation_percent > 100 || (string) $this->situation_percent == '') $this->situation_percent = 100;
|
||||
|
||||
if (empty($this->pa_ht)) $this->pa_ht=0;
|
||||
@ -4462,7 +4451,7 @@ class FactureLigne extends CommonInvoiceLine
|
||||
$sql.= " ".price2num($this->total_localtax1).",";
|
||||
$sql.= " ".price2num($this->total_localtax2);
|
||||
$sql.= ", " . $this->situation_percent;
|
||||
$sql.= ", " . $this->fk_prev_id;
|
||||
$sql.= ", " . (!empty($this->fk_prev_id)?$this->fk_prev_id:"null");
|
||||
$sql.= ", ".(!$this->fk_unit ? 'NULL' : $this->fk_unit);
|
||||
$sql.= ", ".$user->id;
|
||||
$sql.= ", ".$user->id;
|
||||
|
||||
@ -57,7 +57,6 @@ class PaymentTerm // extends CommonObject
|
||||
function __construct($db)
|
||||
{
|
||||
$this->db = $db;
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
@ -332,11 +331,11 @@ class PaymentTerm // extends CommonObject
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
/**
|
||||
* Delete object in database
|
||||
*
|
||||
* @param User $user User that delete
|
||||
* @param int $notrigger 0=launch triggers after, 1=disable triggers
|
||||
* @param User $user User that delete
|
||||
* @param int $notrigger 0=launch triggers after, 1=disable triggers
|
||||
* @return int <0 if KO, >0 if OK
|
||||
*/
|
||||
function delete($user, $notrigger=0)
|
||||
|
||||
@ -155,7 +155,7 @@ if ($id > 0 || ! empty($ref))
|
||||
$morehtmlref.=$form->editfieldkey("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', 0, 1);
|
||||
$morehtmlref.=$form->editfieldval("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', null, null, '', 1);
|
||||
// Thirdparty
|
||||
$morehtmlref.='<br>'.$langs->trans('ThirdParty') . ' : ' . $object->thirdparty->getNomUrl(1);
|
||||
$morehtmlref.='<br>'.$langs->trans('ThirdParty') . ' : ' . $object->thirdparty->getNomUrl(1,'customer');
|
||||
// Project
|
||||
if (! empty($conf->projet->enabled))
|
||||
{
|
||||
|
||||
@ -125,7 +125,7 @@ if ($id > 0 || ! empty($ref))
|
||||
$morehtmlref.=$form->editfieldkey("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', 0, 1);
|
||||
$morehtmlref.=$form->editfieldval("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', null, null, '', 1);
|
||||
// Thirdparty
|
||||
$morehtmlref.='<br>'.$langs->trans('ThirdParty') . ' : ' . $object->thirdparty->getNomUrl(1);
|
||||
$morehtmlref.='<br>'.$langs->trans('ThirdParty') . ' : ' . $object->thirdparty->getNomUrl(1,'customer');
|
||||
// Project
|
||||
if (! empty($conf->projet->enabled))
|
||||
{
|
||||
|
||||
@ -69,7 +69,7 @@ $morehtmlref='<div class="refidno">';
|
||||
$morehtmlref.=$form->editfieldkey("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', 0, 1);
|
||||
$morehtmlref.=$form->editfieldval("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', null, null, '', 1);
|
||||
// Thirdparty
|
||||
$morehtmlref.='<br>'.$langs->trans('ThirdParty') . ' : ' . $object->thirdparty->getNomUrl(1);
|
||||
$morehtmlref.='<br>'.$langs->trans('ThirdParty') . ' : ' . $object->thirdparty->getNomUrl(1,'customer');
|
||||
// Project
|
||||
if (! empty($conf->projet->enabled))
|
||||
{
|
||||
|
||||
@ -96,7 +96,7 @@ $day_lim = GETPOST('day_lim','int');
|
||||
$month_lim = GETPOST('month_lim','int');
|
||||
$year_lim = GETPOST('year_lim','int');
|
||||
|
||||
$option = GETPOST('option');
|
||||
$option = GETPOST('search_option');
|
||||
if ($option == 'late') {
|
||||
$search_status = '1';
|
||||
}
|
||||
@ -276,7 +276,7 @@ if ($massaction == 'withdrawrequest')
|
||||
$error++;
|
||||
setEventMessages($objecttmp->ref.' '.$langs->trans("AmountMustBePositive"), $objecttmp->errors, 'errors');
|
||||
}
|
||||
if(!($objecttmp->statut > Facture::STATUS_DRAFT)){
|
||||
if (!($objecttmp->statut > Facture::STATUS_DRAFT)){
|
||||
$error++;
|
||||
setEventMessages($objecttmp->ref.' '.$langs->trans("Draft"), $objecttmp->errors, 'errors');
|
||||
}
|
||||
@ -298,11 +298,11 @@ if ($massaction == 'withdrawrequest')
|
||||
$numprlv = $db->num_rows($result_sql);
|
||||
}
|
||||
|
||||
if($numprlv>0){
|
||||
if ($numprlv>0){
|
||||
$error++;
|
||||
setEventMessages($objecttmp->ref.' '.$langs->trans("RequestAlreadyDone"), $objecttmp->errors, 'errors');
|
||||
}
|
||||
if(!empty($objecttmp->mode_reglement_id ) && $objecttmp->mode_reglement_id != 3){
|
||||
if (!empty($objecttmp->mode_reglement_code ) && $objecttmp->mode_reglement_code != 'PRE'){
|
||||
$error++;
|
||||
setEventMessages($objecttmp->ref.' '.$langs->trans("BadPaymentMethod"), $objecttmp->errors, 'errors');
|
||||
}
|
||||
@ -560,7 +560,7 @@ if ($resql)
|
||||
if ($search_status != '') $param.='&search_status='.urlencode($search_status);
|
||||
if ($search_paymentmode > 0) $param.='search_paymentmode='.urlencode($search_paymentmode);
|
||||
if ($show_files) $param.='&show_files=' .$show_files;
|
||||
if ($option) $param.="&option=".$option;
|
||||
if ($option) $param.="&search_option=".$option;
|
||||
if ($optioncss != '') $param.='&optioncss='.$optioncss;
|
||||
// Add $param from extra fields
|
||||
include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
|
||||
@ -714,7 +714,7 @@ if ($resql)
|
||||
if (! empty($conf->global->MAIN_LIST_FILTER_ON_DAY)) print '<input class="flat valignmiddle" type="text" size="1" maxlength="2" name="day_lim" value="'.dol_escape_htmltag($day_lim).'">';
|
||||
print '<input class="flat valignmiddle" type="text" size="1" maxlength="2" name="month_lim" value="'.dol_escape_htmltag($month_lim).'">';
|
||||
$formother->select_year($year_lim?$year_lim:-1,'year_lim',1, 20, 5, 0, 0, '', 'widthauto valignmiddle');
|
||||
print '<br><input type="checkbox" name="option" value="late"'.($option == 'late'?' checked':'').'> '.$langs->trans("Late");
|
||||
print '<br><input type="checkbox" name="search_option" value="late"'.($option == 'late'?' checked':'').'> '.$langs->trans("Late");
|
||||
print '</td>';
|
||||
}
|
||||
// Project
|
||||
|
||||
@ -92,7 +92,7 @@ if ($id > 0 || ! empty($ref))
|
||||
$morehtmlref.=$form->editfieldkey("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', 0, 1);
|
||||
$morehtmlref.=$form->editfieldval("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', null, null, '', 1);
|
||||
// Thirdparty
|
||||
$morehtmlref.='<br>'.$langs->trans('ThirdParty') . ' : ' . $object->thirdparty->getNomUrl(1);
|
||||
$morehtmlref.='<br>'.$langs->trans('ThirdParty') . ' : ' . $object->thirdparty->getNomUrl(1,'customer');
|
||||
// Project
|
||||
if (! empty($conf->projet->enabled))
|
||||
{
|
||||
|
||||
@ -140,8 +140,16 @@ if ($object->id > 0)
|
||||
if ($object->paye) $resteapayer=0;
|
||||
$resteapayeraffiche=$resteapayer;
|
||||
|
||||
$absolute_discount=$object->thirdparty->getAvailableDiscounts('','fk_facture_source IS NULL');
|
||||
$absolute_creditnote=$object->thirdparty->getAvailableDiscounts('','fk_facture_source IS NOT NULL');
|
||||
if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
|
||||
$filterabsolutediscount = "fk_facture_source IS NULL"; // If we want deposit to be substracted to payments only and not to total of final invoice
|
||||
$filtercreditnote = "fk_facture_source IS NOT NULL"; // If we want deposit to be substracted to payments only and not to total of final invoice
|
||||
} else {
|
||||
$filterabsolutediscount = "fk_facture_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS RECEIVED)%')";
|
||||
$filtercreditnote = "fk_facture_source IS NOT NULL AND (description NOT LIKE '(DEPOSIT)%' OR description LIKE '(EXCESS RECEIVED)%')";
|
||||
}
|
||||
|
||||
$absolute_discount=$object->thirdparty->getAvailableDiscounts('',$filterabsolutediscount);
|
||||
$absolute_creditnote=$object->thirdparty->getAvailableDiscounts('',$filtercreditnote);
|
||||
$absolute_discount=price2num($absolute_discount,'MT');
|
||||
$absolute_creditnote=price2num($absolute_creditnote,'MT');
|
||||
|
||||
@ -253,61 +261,13 @@ if ($object->id > 0)
|
||||
|
||||
// Discounts
|
||||
print '<tr><td>'.$langs->trans('Discounts').'</td><td colspan="3">';
|
||||
if ($object->thirdparty->remise_percent) print $langs->trans("CompanyHasRelativeDiscount",$object->thirdparty->remise_percent);
|
||||
else print $langs->trans("CompanyHasNoRelativeDiscount");
|
||||
print '. ';
|
||||
if ($absolute_discount > 0)
|
||||
{
|
||||
if ($object->statut > Facture::STATUS_DRAFT || $object->type == Facture::TYPE_CREDIT_NOTE || $object->type == Facture::TYPE_DEPOSIT)
|
||||
{
|
||||
if ($object->statut == Facture::STATUS_DRAFT)
|
||||
{
|
||||
print $langs->trans("CompanyHasAbsoluteDiscount",price($absolute_discount),$langs->transnoentities("Currency".$conf->currency)).'. ';
|
||||
}
|
||||
else
|
||||
{
|
||||
if ($object->statut < Facture::STATUS_VALIDATED || $object->type == Facture::TYPE_CREDIT_NOTE || $object->type == Facture::TYPE_DEPOSIT)
|
||||
{
|
||||
$text=$langs->trans("CompanyHasAbsoluteDiscount",price($absolute_discount),$langs->transnoentities("Currency".$conf->currency));
|
||||
print '<br>'.$text.'.<br>';
|
||||
}
|
||||
else
|
||||
{
|
||||
$text=$langs->trans("CompanyHasAbsoluteDiscount",price($absolute_discount),$langs->transnoentities("Currency".$conf->currency));
|
||||
$text2=$langs->trans("AbsoluteDiscountUse");
|
||||
print $form->textwithpicto($text,$text2);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Remise dispo de type non avoir
|
||||
$filter='fk_facture_source IS NULL';
|
||||
print '<br>';
|
||||
$form->form_remise_dispo($_SERVER["PHP_SELF"].'?id='.$object->id,0,'remise_id',$object->thirdparty->id,$absolute_discount,$filter,$resteapayer,'',1);
|
||||
}
|
||||
}
|
||||
if ($absolute_creditnote > 0)
|
||||
{
|
||||
// If validated, we show link "add credit note to payment"
|
||||
if ($object->statut != Facture::STATUS_VALIDATED || $object->type == Facture::TYPE_DEPOSIT || $object->type == Facture::TYPE_CREDIT_NOTE)
|
||||
{
|
||||
if ($object->statut == Facture::STATUS_DRAFT && $object->type != Facture::TYPE_DEPOSIT)
|
||||
{
|
||||
$text=$langs->trans("CompanyHasCreditNote",price($absolute_creditnote),$langs->transnoentities("Currency".$conf->currency));
|
||||
print $form->textwithpicto($text,$langs->trans("CreditNoteDepositUse"));
|
||||
}
|
||||
else print $langs->trans("CompanyHasCreditNote",price($absolute_creditnote),$langs->transnoentities("Currency".$conf->currency)).'.';
|
||||
}
|
||||
else
|
||||
{
|
||||
// Remise dispo de type avoir
|
||||
$filter='fk_facture_source IS NOT NULL';
|
||||
if (! $absolute_discount) print '<br>';
|
||||
$form->form_remise_dispo($_SERVER["PHP_SELF"].'?id='.$object->id,0,'remise_id_for_payment',$object->thirdparty->id,$absolute_creditnote,$filter,$resteapayer,'',1);
|
||||
}
|
||||
}
|
||||
if (! $absolute_discount && ! $absolute_creditnote) print $langs->trans("CompanyHasNoAbsoluteDiscount").'.';
|
||||
|
||||
$thirdparty = $object->thirdparty;
|
||||
$discount_type = 0;
|
||||
$backtopage = urlencode($_SERVER["PHP_SELF"] . '?facid=' . $object->id);
|
||||
$cannotApplyDiscount = 1;
|
||||
include DOL_DOCUMENT_ROOT.'/core/tpl/object_discounts.tpl.php';
|
||||
|
||||
print '</td></tr>';
|
||||
|
||||
// Date invoice
|
||||
|
||||
@ -199,7 +199,7 @@ if (! empty($conf->facture->enabled) && $user->rights->facture->lire)
|
||||
print $facturestatic->getNomUrl(1,'');
|
||||
print '</td>';
|
||||
print '<td class="nowrap">';
|
||||
print $companystatic->getNomUrl(1,'',16);
|
||||
print $companystatic->getNomUrl(1,'customer',16);
|
||||
print '</td>';
|
||||
print '<td align="right" class="nowrap">'.price($obj->total_ttc).'</td>';
|
||||
print '</tr>';
|
||||
|
||||
@ -726,16 +726,12 @@ class BonPrelevement extends CommonObject
|
||||
$sql = "SELECT count(f.rowid) as nb";
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX."facture as f";
|
||||
$sql.= ", ".MAIN_DB_PREFIX."prelevement_facture_demande as pfd";
|
||||
//if ($banque || $agence) $sql.=", ".MAIN_DB_PREFIX."societe_rib as sr";
|
||||
$sql.= " WHERE f.fk_statut = 1";
|
||||
$sql.= " AND f.entity = ".$conf->entity;
|
||||
$sql.= " AND f.rowid = pfd.fk_facture";
|
||||
$sql.= " AND f.paye = 0";
|
||||
$sql.= " AND pfd.traite = 0";
|
||||
$sql.= " AND f.total_ttc > 0";
|
||||
//if ($banque || $agence) $sql.= " AND f.fk_soc = sr.rowid";
|
||||
//if ($banque) $sql.= " AND sr.code_banque = '".$conf->global->PRELEVEMENT_CODE_BANQUE."'";
|
||||
//if ($agence) $sql.= " AND sr.code_guichet = '".$conf->global->PRELEVEMENT_CODE_GUICHET."'";
|
||||
|
||||
dol_syslog(get_class($this)."::SommeAPrelever");
|
||||
$resql = $this->db->query($sql);
|
||||
@ -805,9 +801,8 @@ class BonPrelevement extends CommonObject
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX."facture as f";
|
||||
$sql.= ", ".MAIN_DB_PREFIX."societe as s";
|
||||
$sql.= ", ".MAIN_DB_PREFIX."prelevement_facture_demande as pfd";
|
||||
//if ($banque || $agence) $sql.= ", ".MAIN_DB_PREFIX."societe_rib as sr";
|
||||
$sql.= " WHERE f.rowid = pfd.fk_facture";
|
||||
$sql.= " AND f.entity = ".$conf->entity;
|
||||
$sql.= " AND f.entity IN (".getEntity('facture').')';
|
||||
$sql.= " AND s.rowid = f.fk_soc";
|
||||
//if ($banque || $agence) $sql.= " AND s.rowid = sr.fk_soc";
|
||||
$sql.= " AND f.fk_statut = 1";
|
||||
@ -1340,6 +1335,7 @@ class BonPrelevement extends CommonObject
|
||||
$sql.= " AND soc.rowid = f.fk_soc";
|
||||
$sql.= " AND rib.fk_soc = f.fk_soc";
|
||||
$sql.= " AND rib.default_rib = 1";
|
||||
$sql.= " AND rib.type = 'ban'";
|
||||
//print $sql;
|
||||
|
||||
// Define $fileDebiteurSection. One section DrctDbtTxInf per invoice.
|
||||
|
||||
@ -7,6 +7,7 @@
|
||||
* Copyright (C) 2013 Cédric Salvador <csalvador@gpcsolutions.fr>
|
||||
* Copyright (C) 2013 Alexandre Spangaro <aspangaro.dolibarr@gmail.com>
|
||||
* Copyright (C) 2015 Jean-François Ferry <jfefe@aternatik.fr>
|
||||
* Copyright (C) 2018 Nicolas ZABOURI <info@inovea-conseil.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@ -133,6 +134,7 @@ $fieldstosearchall = array(
|
||||
'p.firstname'=>'Firstname',
|
||||
'p.email'=>'EMail',
|
||||
's.nom'=>"ThirdParty",
|
||||
'p.phone'=>"Phone",
|
||||
);
|
||||
|
||||
// Definition of fields for list
|
||||
|
||||
@ -899,17 +899,20 @@ class Contrat extends CommonObject
|
||||
if ($result > 0)
|
||||
{
|
||||
$modCodeContract = new $module();
|
||||
}
|
||||
|
||||
if (!empty($modCodeContract->code_auto)) {
|
||||
// Mise a jour ref
|
||||
$sql = 'UPDATE '.MAIN_DB_PREFIX."contrat SET ref='(PROV".$this->id.")' WHERE rowid=".$this->id;
|
||||
if ($this->db->query($sql))
|
||||
{
|
||||
if ($this->id)
|
||||
if (!empty($modCodeContract->code_auto)) {
|
||||
// Mise a jour ref
|
||||
$sql = 'UPDATE '.MAIN_DB_PREFIX."contrat SET ref='(PROV".$this->id.")' WHERE rowid=".$this->id;
|
||||
if ($this->db->query($sql))
|
||||
{
|
||||
$this->ref="(PROV".$this->id.")";
|
||||
if ($this->id)
|
||||
{
|
||||
$this->ref="(PROV".$this->id.")";
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$error++;
|
||||
$this->error='Failed to get PROV number';
|
||||
}
|
||||
}
|
||||
|
||||
@ -1336,6 +1339,7 @@ class Contrat extends CommonObject
|
||||
function addline($desc, $pu_ht, $qty, $txtva, $txlocaltax1, $txlocaltax2, $fk_product, $remise_percent, $date_start, $date_end, $price_base_type='HT', $pu_ttc=0.0, $info_bits=0, $fk_fournprice=null, $pa_ht = 0,$array_options=0, $fk_unit = null, $rang=0)
|
||||
{
|
||||
global $user, $langs, $conf, $mysoc;
|
||||
$error=0;
|
||||
|
||||
dol_syslog(get_class($this)."::addline $desc, $pu_ht, $qty, $txtva, $txlocaltax1, $txlocaltax2, $fk_product, $remise_percent, $date_start, $date_end, $price_base_type, $pu_ttc, $info_bits, $rang");
|
||||
|
||||
@ -1544,6 +1548,8 @@ class Contrat extends CommonObject
|
||||
{
|
||||
global $user, $conf, $langs, $mysoc;
|
||||
|
||||
$error=0;
|
||||
|
||||
// Clean parameters
|
||||
$qty=trim($qty);
|
||||
$desc=trim($desc);
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
<?php
|
||||
/* Copyright (C) 2015-2017 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||
* Copyright (C) 2018 Nicolas ZABOURI <info@inovea-conseil.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@ -973,7 +974,41 @@ if (! $error && $massaction == 'validate' && $permtocreate)
|
||||
//var_dump($listofobjectthirdparties);exit;
|
||||
}
|
||||
}
|
||||
// Closed records
|
||||
if (!$error && $massaction == 'closed' && $objectclass == "Propal" && $permtoclose) {
|
||||
$db->begin();
|
||||
|
||||
$objecttmp = new $objectclass($db);
|
||||
$nbok = 0;
|
||||
foreach ($toselect as $toselectid) {
|
||||
$result = $objecttmp->fetch($toselectid);
|
||||
if ($result > 0) {
|
||||
$result = $objecttmp->cloture($user, 3);
|
||||
if ($result <= 0) {
|
||||
setEventMessages($objecttmp->error, $objecttmp->errors, 'errors');
|
||||
$error++;
|
||||
break;
|
||||
} else
|
||||
$nbok++;
|
||||
}
|
||||
else {
|
||||
setEventMessages($objecttmp->error, $objecttmp->errors, 'errors');
|
||||
$error++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!$error) {
|
||||
if ($nbok > 1)
|
||||
setEventMessages($langs->trans("RecordsModified", $nbok), null, 'mesgs');
|
||||
else
|
||||
setEventMessages($langs->trans("RecordsModified", $nbok), null, 'mesgs');
|
||||
$db->commit();
|
||||
}
|
||||
else {
|
||||
$db->rollback();
|
||||
}
|
||||
}
|
||||
// Delete record from mass action (massaction = 'delete' for direct delete, action/confirm='delete'/'yes' with a confirmation step before)
|
||||
if (! $error && ($massaction == 'delete' || ($action == 'delete' && $confirm == 'yes')) && $permtodelete)
|
||||
{
|
||||
|
||||
@ -318,7 +318,6 @@ if (($action == 'send' || $action == 'relance') && ! $_POST['addfile'] && ! $_PO
|
||||
$filename = $attachedfiles['names'];
|
||||
$mimetype = $attachedfiles['mimes'];
|
||||
|
||||
|
||||
// Feature to push mail sent into Sent folder
|
||||
/* This code must be now included into the hook mail, method sendMailAfter
|
||||
if (! empty($conf->dolimail->enabled))
|
||||
|
||||
@ -80,14 +80,16 @@ class CMailFile
|
||||
var $atleastoneimage=0; // at least one image file with file=xxx.ext into content (TODO Debug this. How can this case be tested. Remove if not used).
|
||||
var $html_images=array();
|
||||
var $images_encoded=array();
|
||||
var $image_types = array('gif' => 'image/gif',
|
||||
'jpg' => 'image/jpeg',
|
||||
'jpeg' => 'image/jpeg',
|
||||
'jpe' => 'image/jpeg',
|
||||
'bmp' => 'image/bmp',
|
||||
'png' => 'image/png',
|
||||
'tif' => 'image/tiff',
|
||||
'tiff' => 'image/tiff');
|
||||
var $image_types = array(
|
||||
'gif' => 'image/gif',
|
||||
'jpg' => 'image/jpeg',
|
||||
'jpeg' => 'image/jpeg',
|
||||
'jpe' => 'image/jpeg',
|
||||
'bmp' => 'image/bmp',
|
||||
'png' => 'image/png',
|
||||
'tif' => 'image/tiff',
|
||||
'tiff' => 'image/tiff',
|
||||
);
|
||||
|
||||
|
||||
/**
|
||||
@ -396,13 +398,32 @@ class CMailFile
|
||||
// Use Swift Mailer library
|
||||
// ------------------------------------------
|
||||
|
||||
$host = dol_getprefix('email');
|
||||
$host = dol_getprefix('email');
|
||||
|
||||
require_once DOL_DOCUMENT_ROOT.'/includes/swiftmailer/lexer/lib/Doctrine/Common/Lexer/AbstractLexer.php';
|
||||
|
||||
require_once DOL_DOCUMENT_ROOT.'/includes/swiftmailer/egulias/email-validator/EmailValidator/EmailParser.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/includes/swiftmailer/egulias/email-validator/EmailValidator/EmailLexer.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/includes/swiftmailer/egulias/email-validator/EmailValidator/EmailValidator.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/includes/swiftmailer/egulias/email-validator/EmailValidator/Warning/Warning.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/includes/swiftmailer/egulias/email-validator/EmailValidator/Warning/LocalTooLong.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/includes/swiftmailer/egulias/email-validator/EmailValidator/Parser/Parser.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/includes/swiftmailer/egulias/email-validator/EmailValidator/Parser/DomainPart.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/includes/swiftmailer/egulias/email-validator/EmailValidator/Parser/LocalPart.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/includes/swiftmailer/egulias/email-validator/EmailValidator/Validation/EmailValidation.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/includes/swiftmailer/egulias/email-validator/EmailValidator/Validation/RFCValidation.php';
|
||||
|
||||
require_once DOL_DOCUMENT_ROOT.'/includes/swiftmailer/lib/classes/Swift/InputByteStream.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/includes/swiftmailer/lib/classes/Swift/Signer.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/includes/swiftmailer/lib/classes/Swift/Signers/HeaderSigner.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/includes/swiftmailer/lib/classes/Swift/Signers/DKIMSigner.php';
|
||||
//require_once DOL_DOCUMENT_ROOT.'/includes/swiftmailer/lib/classes/Swift/SignedMessage.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/includes/swiftmailer/lib/swift_required.php';
|
||||
// Create the message
|
||||
$this->message = Swift_Message::newInstance();
|
||||
|
||||
// Adding a trackid header to a message
|
||||
//$this->message = Swift_Message::newInstance();
|
||||
$this->message = new Swift_Message();
|
||||
//$this->message = new Swift_SignedMessage();
|
||||
// Adding a trackid header to a message
|
||||
$headers = $this->message->getHeaders();
|
||||
$headers->addTextHeader('X-Dolibarr-TRACKID', $trackid);
|
||||
$headerID = time() . '.swiftmailer-dolibarr-' . $trackid . '@' . $host;
|
||||
@ -452,11 +473,11 @@ class CMailFile
|
||||
if ($this->msgishtml) {
|
||||
$this->message->setBody($msg,'text/html');
|
||||
// And optionally an alternative body
|
||||
//$this->message->addPart('Here is the message itself', 'text/plain');
|
||||
$this->message->addPart(html_entity_decode(strip_tags($msg)), 'text/plain');
|
||||
} else {
|
||||
$this->message->setBody($msg,'text/plain');
|
||||
// And optionally an alternative body
|
||||
//$this->message->addPart('<q>Here is the message itself</q>', 'text/html');
|
||||
$this->message->addPart($msg, 'text/html');
|
||||
}
|
||||
|
||||
if ($this->atleastonefile)
|
||||
@ -494,7 +515,7 @@ class CMailFile
|
||||
global $conf,$db,$langs;
|
||||
|
||||
$errorlevel=error_reporting();
|
||||
error_reporting($errorlevel ^ E_WARNING); // Desactive warnings
|
||||
//error_reporting($errorlevel ^ E_WARNING); // Desactive warnings
|
||||
|
||||
$res=false;
|
||||
|
||||
@ -745,21 +766,30 @@ class CMailFile
|
||||
if (empty($conf->global->$keyforsmtpport)) $conf->global->$keyforsmtpport=ini_get('smtp_port');
|
||||
|
||||
// If we use SSL/TLS
|
||||
$server=$conf->global->$keyforsmtpserver;
|
||||
$secure='';
|
||||
$server = $conf->global->$keyforsmtpserver;
|
||||
$secure = '';
|
||||
if (! empty($conf->global->$keyfortls) && function_exists('openssl_open')) $secure='ssl';
|
||||
if (! empty($conf->global->$keyforstarttls) && function_exists('openssl_open')) $secure='tls';
|
||||
|
||||
$this->transport = Swift_SmtpTransport::newInstance($server, $conf->global->$keyforsmtpport, $secure);
|
||||
$this->transport = new Swift_SmtpTransport($server, $conf->global->$keyforsmtpport, $secure);
|
||||
|
||||
if (! empty($conf->global->$keyforsmtpid)) $this->transport->setUsername($conf->global->$keyforsmtpid);
|
||||
if (! empty($conf->global->$keyforsmtppw)) $this->transport->setPassword($conf->global->$keyforsmtppw);
|
||||
//$smtps->_msgReplyTo = 'reply@web.com';
|
||||
|
||||
// Create the Mailer using your created Transport
|
||||
$this->mailer = Swift_Mailer::newInstance($this->transport);
|
||||
$this->mailer = new Swift_Mailer($this->transport);
|
||||
|
||||
if (! empty($conf->global->MAIN_MAIL_DEBUG)) {
|
||||
// DKIM SIGN
|
||||
if ($conf->global->MAIN_MAIL_EMAIL_DKIM_ENABLED) {
|
||||
$privateKey = $conf->global->MAIN_MAIL_EMAIL_DKIM_PRIVATE_KEY;
|
||||
$domainName = $conf->global->MAIN_MAIL_EMAIL_DKIM_DOMAIN;
|
||||
$selector = $conf->global->MAIN_MAIL_EMAIL_DKIM_SELECTOR;
|
||||
$signer = new Swift_Signers_DKIMSigner($privateKey, $domainName, $selector);
|
||||
$this->message->attachSigner($signer);
|
||||
}
|
||||
|
||||
if (! empty($conf->global->MAIN_MAIL_DEBUG)) {
|
||||
// To use the ArrayLogger
|
||||
$this->logger = new Swift_Plugins_Loggers_ArrayLogger();
|
||||
// Or to use the Echo Logger
|
||||
@ -775,7 +805,7 @@ class CMailFile
|
||||
if (! empty($conf->global->MAIN_MAIL_DEBUG)) $this->dump_mail();
|
||||
|
||||
$res = true;
|
||||
if (! empty($this->error) && ! $result) {
|
||||
if (! empty($this->error) || ! $result) {
|
||||
dol_syslog("CMailFile::sendfile: mail end error=".$this->error, LOG_ERR);
|
||||
$res=false;
|
||||
} else {
|
||||
|
||||
@ -44,7 +44,6 @@ abstract class CommonDocGenerator
|
||||
*/
|
||||
public function __construct($db) {
|
||||
$this->db = $db;
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -180,12 +180,6 @@ abstract class CommonInvoice extends CommonObject
|
||||
*/
|
||||
function getSumCreditNotesUsed($multicurrency=0)
|
||||
{
|
||||
if ($this->element == 'facture_fourn' || $this->element == 'invoice_supplier')
|
||||
{
|
||||
// TODO
|
||||
return 0;
|
||||
}
|
||||
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/class/discount.class.php';
|
||||
|
||||
$discountstatic=new DiscountAbsolute($this->db);
|
||||
@ -682,7 +676,7 @@ abstract class CommonInvoiceLine extends CommonObjectLine
|
||||
{
|
||||
/**
|
||||
* Quantity
|
||||
* @var int
|
||||
* @var double
|
||||
*/
|
||||
public $qty;
|
||||
|
||||
|
||||
@ -3984,6 +3984,12 @@ abstract class CommonObject
|
||||
$discount->fetch($line->fk_remise_except);
|
||||
$this->tpl['description'] = $langs->transnoentities("DiscountFromExcessReceived",$discount->getNomUrl(0));
|
||||
}
|
||||
elseif ($line->desc == '(EXCESS PAID)')
|
||||
{
|
||||
$discount=new DiscountAbsolute($this->db);
|
||||
$discount->fetch($line->fk_remise_except);
|
||||
$this->tpl['description'] = $langs->transnoentities("DiscountFromExcessPaid",$discount->getNomUrl(0));
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->tpl['description'] = dol_trunc($line->desc,60);
|
||||
@ -5521,7 +5527,7 @@ abstract class CommonObject
|
||||
$label = $val['label'];
|
||||
$type = $val['type'];
|
||||
$size = $val['css'];
|
||||
|
||||
|
||||
// Convert var to be able to share same code than showOutputField of extrafields
|
||||
if (preg_match('/varchar\((\d+)\)/', $type, $reg))
|
||||
{
|
||||
@ -5985,7 +5991,7 @@ abstract class CommonObject
|
||||
jQuery(document).ready(function() {
|
||||
function showOptions(child_list, parent_list)
|
||||
{
|
||||
var val = $("select[name=\"options_"+parent_list+"\"]").val();
|
||||
var val = $("select[name="+parent_list+"]").val();
|
||||
var parentVal = parent_list + ":" + val;
|
||||
if(val > 0) {
|
||||
$("select[name=\""+child_list+"\"] option[parent]").hide();
|
||||
@ -6197,7 +6203,7 @@ abstract class CommonObject
|
||||
{
|
||||
if(is_array($info))
|
||||
{
|
||||
if(isset($info['type']) && ($info['type']=='int' || $info['type']=='integer' )) return true;
|
||||
if(isset($info['type']) && ($info['type']=='int' || preg_match('/^integer/i',$info['type']) ) ) return true;
|
||||
else return false;
|
||||
}
|
||||
else return false;
|
||||
|
||||
@ -34,6 +34,7 @@ class DiscountAbsolute
|
||||
|
||||
public $id; // Id discount
|
||||
public $fk_soc;
|
||||
public $discount_type; // 0 => customer discount, 1 => supplier discount
|
||||
public $amount_ht; //
|
||||
public $amount_tva; //
|
||||
public $amount_ttc; //
|
||||
@ -45,6 +46,7 @@ class DiscountAbsolute
|
||||
public $fk_facture; // Id invoice when a discount line is used into an invoice (for credit note)
|
||||
public $fk_facture_source; // Id facture avoir a l'origine de la remise
|
||||
public $ref_facture_source; // Ref facture avoir a l'origine de la remise
|
||||
public $ref_invoice_supplier_source;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
@ -60,33 +62,36 @@ class DiscountAbsolute
|
||||
/**
|
||||
* Load object from database into memory
|
||||
*
|
||||
* @param int $rowid id discount to load
|
||||
* @param int $fk_facture_source fk_facture_source
|
||||
* @return int <0 if KO, =0 if not found, >0 if OK
|
||||
* @param int $rowid id discount to load
|
||||
* @param int $fk_facture_source fk_facture_source
|
||||
* @param int $fk_invoice_supplier_source fk_invoice_supplier_source
|
||||
* @return int <0 if KO, =0 if not found, >0 if OK
|
||||
*/
|
||||
function fetch($rowid, $fk_facture_source=0)
|
||||
function fetch($rowid, $fk_facture_source=0, $fk_invoice_supplier_source=0)
|
||||
{
|
||||
global $conf;
|
||||
|
||||
// Check parameters
|
||||
if (! $rowid && ! $fk_facture_source)
|
||||
if (! $rowid && ! $fk_facture_source && ! $fk_invoice_supplier_source)
|
||||
{
|
||||
$this->error='ErrorBadParameters';
|
||||
return -1;
|
||||
}
|
||||
|
||||
$sql = "SELECT sr.rowid, sr.fk_soc,";
|
||||
$sql = "SELECT sr.rowid, sr.fk_soc, sr.discount_type,";
|
||||
$sql.= " sr.fk_user,";
|
||||
$sql.= " sr.amount_ht, sr.amount_tva, sr.amount_ttc, sr.tva_tx,";
|
||||
$sql.= " sr.multicurrency_amount_ht, sr.multicurrency_amount_tva, sr.multicurrency_amount_ttc,";
|
||||
$sql.= " sr.fk_facture_line, sr.fk_facture, sr.fk_facture_source, sr.description,";
|
||||
$sql.= " sr.fk_facture_line, sr.fk_facture, sr.fk_facture_source, sr.fk_invoice_supplier_line, sr.fk_invoice_supplier, sr.fk_invoice_supplier_source, sr.description,";
|
||||
$sql.= " sr.datec,";
|
||||
$sql.= " f.facnumber as ref_facture_source";
|
||||
$sql.= " f.facnumber as ref_facture_source, fsup.facnumber as ref_invoice_supplier_source";
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX."societe_remise_except as sr";
|
||||
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."facture as f ON sr.fk_facture_source = f.rowid";
|
||||
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."facture as fsup ON sr.fk_invoice_supplier_source = fsup.rowid";
|
||||
$sql.= " WHERE sr.entity = " . $conf->entity;
|
||||
if ($rowid) $sql.= " AND sr.rowid=".$rowid;
|
||||
if ($fk_facture_source) $sql.= " AND sr.fk_facture_source=".$fk_facture_source;
|
||||
if ($fk_invoice_supplier_source) $sql.= " AND sr.fk_invoice_supplier_source=".$fk_invoice_supplier_source;
|
||||
|
||||
dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
|
||||
$resql = $this->db->query($sql);
|
||||
@ -98,6 +103,7 @@ class DiscountAbsolute
|
||||
|
||||
$this->id = $obj->rowid;
|
||||
$this->fk_soc = $obj->fk_soc;
|
||||
$this->discount_type = $obj->discount_type;
|
||||
|
||||
$this->amount_ht = $obj->amount_ht;
|
||||
$this->amount_tva = $obj->amount_tva;
|
||||
@ -113,6 +119,10 @@ class DiscountAbsolute
|
||||
$this->fk_facture = $obj->fk_facture;
|
||||
$this->fk_facture_source = $obj->fk_facture_source; // Id avoir source
|
||||
$this->ref_facture_source = $obj->ref_facture_source; // Ref avoir source
|
||||
$this->fk_invoice_supplier_line = $obj->fk_invoice_supplier_line;
|
||||
$this->fk_invoice_supplier = $obj->fk_invoice_supplier;
|
||||
$this->fk_invoice_supplier_source = $obj->fk_invoice_supplier_source; // Id avoir source
|
||||
$this->ref_invoice_supplier_source = $obj->ref_invoice_supplier_source; // Ref avoir source
|
||||
$this->description = $obj->description;
|
||||
$this->datec = $this->db->jdate($obj->datec);
|
||||
|
||||
@ -159,13 +169,14 @@ class DiscountAbsolute
|
||||
|
||||
// Insert request
|
||||
$sql = "INSERT INTO ".MAIN_DB_PREFIX."societe_remise_except";
|
||||
$sql.= " (entity, datec, fk_soc, fk_user, description,";
|
||||
$sql.= " (entity, datec, fk_soc, discount_type, fk_user, description,";
|
||||
$sql.= " amount_ht, amount_tva, amount_ttc, tva_tx,";
|
||||
$sql.= " fk_facture_source";
|
||||
$sql.= " fk_facture_source, fk_invoice_supplier_source";
|
||||
$sql.= ")";
|
||||
$sql.= " VALUES (".$conf->entity.", '".$this->db->idate($this->datec!=''?$this->datec:dol_now())."', ".$this->fk_soc.", ".$user->id.", '".$this->db->escape($this->description)."',";
|
||||
$sql.= " VALUES (".$conf->entity.", '".$this->db->idate($this->datec!=''?$this->datec:dol_now())."', ".$this->fk_soc.", ".(empty($this->discount_type)?0:intval($this->discount_type)).", ".$user->id.", '".$this->db->escape($this->description)."',";
|
||||
$sql.= " ".$this->amount_ht.", ".$this->amount_tva.", ".$this->amount_ttc.", ".$this->tva_tx.",";
|
||||
$sql.= " ".($this->fk_facture_source ? "'".$this->db->escape($this->fk_facture_source)."'":"null");
|
||||
$sql.= " ".($this->fk_facture_source ? "'".$this->db->escape($this->fk_facture_source)."'":"null").",";
|
||||
$sql.= " ".($this->fk_invoice_supplier_source ? "'".$this->db->escape($this->fk_invoice_supplier_source)."'":"null");
|
||||
$sql.= ")";
|
||||
|
||||
dol_syslog(get_class($this)."::create", LOG_DEBUG);
|
||||
@ -220,15 +231,46 @@ class DiscountAbsolute
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
// Check if we can remove the discount
|
||||
if ($this->fk_invoice_supplier_source)
|
||||
{
|
||||
$sql="SELECT COUNT(rowid) as nb";
|
||||
$sql.=" FROM ".MAIN_DB_PREFIX."societe_remise_except";
|
||||
$sql.=" WHERE (fk_invoice_supplier_line IS NOT NULL"; // Not used as absolute simple discount
|
||||
$sql.=" OR fk_invoice_supplier IS NOT NULL)"; // Not used as credit note and not used as deposit
|
||||
$sql.=" AND fk_invoice_supplier_source = ".$this->fk_invoice_supplier_source;
|
||||
//$sql.=" AND rowid != ".$this->id;
|
||||
|
||||
dol_syslog(get_class($this)."::delete Check if we can remove discount", LOG_DEBUG);
|
||||
$resql=$this->db->query($sql);
|
||||
if ($resql)
|
||||
{
|
||||
$obj = $this->db->fetch_object($resql);
|
||||
if ($obj->nb > 0)
|
||||
{
|
||||
$this->error='ErrorThisPartOrAnotherIsAlreadyUsedSoDiscountSerieCantBeRemoved';
|
||||
return -2;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
dol_print_error($this->db);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
$this->db->begin();
|
||||
|
||||
// Delete but only if not used
|
||||
$sql = "DELETE FROM ".MAIN_DB_PREFIX."societe_remise_except ";
|
||||
if ($this->fk_facture_source) $sql.= " WHERE fk_facture_source = ".$this->fk_facture_source; // Delete all lines of same serie
|
||||
elseif ($this->fk_invoice_supplier_source) $sql.= " WHERE fk_invoice_supplier_source = ".$this->fk_invoice_supplier_source; // Delete all lines of same serie
|
||||
else $sql.= " WHERE rowid = ".$this->id; // Delete only line
|
||||
$sql.= " AND (fk_facture_line IS NULL"; // Not used as absolute simple discount
|
||||
$sql.= " AND fk_facture IS NULL)"; // Not used as credit note and not used as deposit
|
||||
$sql.= " AND (fk_invoice_supplier_line IS NULL"; // Not used as absolute simple discount
|
||||
$sql.= " AND fk_invoice_supplier IS NULL)"; // Not used as credit note and not used as deposit
|
||||
|
||||
dol_syslog(get_class($this)."::delete Delete discount", LOG_DEBUG);
|
||||
$result=$this->db->query($sql);
|
||||
@ -255,6 +297,26 @@ class DiscountAbsolute
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
elseif($this->fk_invoice_supplier_source) {
|
||||
|
||||
$sql = "UPDATE ".MAIN_DB_PREFIX."facture_fourn";
|
||||
$sql.=" set paye=0, fk_statut=1";
|
||||
$sql.=" WHERE (type = 2 or type = 3) AND rowid=".$this->fk_invoice_supplier_source;
|
||||
|
||||
dol_syslog(get_class($this)."::delete Update credit note or deposit invoice statut", LOG_DEBUG);
|
||||
$result=$this->db->query($sql);
|
||||
if ($result)
|
||||
{
|
||||
$this->db->commit();
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->error=$this->db->lasterror();
|
||||
$this->db->rollback();
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->db->commit();
|
||||
@ -295,16 +357,26 @@ class DiscountAbsolute
|
||||
}
|
||||
|
||||
$sql ="UPDATE ".MAIN_DB_PREFIX."societe_remise_except";
|
||||
if ($rowidline) $sql.=" SET fk_facture_line = ".$rowidline;
|
||||
if ($rowidinvoice) $sql.=" SET fk_facture = ".$rowidinvoice;
|
||||
if(! empty($this->discount_type)) {
|
||||
if ($rowidline) $sql.=" SET fk_invoice_supplier_line = ".$rowidline;
|
||||
if ($rowidinvoice) $sql.=" SET fk_invoice_supplier = ".$rowidinvoice;
|
||||
} else {
|
||||
if ($rowidline) $sql.=" SET fk_facture_line = ".$rowidline;
|
||||
if ($rowidinvoice) $sql.=" SET fk_facture = ".$rowidinvoice;
|
||||
}
|
||||
$sql.=" WHERE rowid = ".$this->id;
|
||||
|
||||
dol_syslog(get_class($this)."::link_to_invoice", LOG_DEBUG);
|
||||
$resql = $this->db->query($sql);
|
||||
if ($resql)
|
||||
{
|
||||
$this->fk_facture_line=$rowidline;
|
||||
$this->fk_facture=$rowidinvoice;
|
||||
if(! empty($this->discount_type)) {
|
||||
$this->fk_invoice_supplier_line=$rowidline;
|
||||
$this->fk_invoice_supplier=$rowidinvoice;
|
||||
} else {
|
||||
$this->fk_facture_line=$rowidline;
|
||||
$this->fk_facture=$rowidinvoice;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
@ -324,7 +396,11 @@ class DiscountAbsolute
|
||||
function unlink_invoice()
|
||||
{
|
||||
$sql ="UPDATE ".MAIN_DB_PREFIX."societe_remise_except";
|
||||
$sql.=" SET fk_facture_line = NULL, fk_facture = NULL";
|
||||
if(! empty($this->discount_type)) {
|
||||
$sql.=" SET fk_invoice_supplier_line = NULL, fk_invoice_supplier = NULL";
|
||||
} else {
|
||||
$sql.=" SET fk_facture_line = NULL, fk_facture = NULL";
|
||||
}
|
||||
$sql.=" WHERE rowid = ".$this->id;
|
||||
|
||||
dol_syslog(get_class($this)."::unlink_invoice", LOG_DEBUG);
|
||||
@ -344,14 +420,14 @@ class DiscountAbsolute
|
||||
/**
|
||||
* Return amount (with tax) of discounts currently available for a company, user or other criteria
|
||||
*
|
||||
* @param Societe $company Object third party for filter
|
||||
* @param User $user Filtre sur un user auteur des remises
|
||||
* @param string $filter Filtre autre
|
||||
* @param int $maxvalue Filter on max value for discount
|
||||
* @param string $mode 'customer' = discounts the customer has, 'supplier' = discount i have at this supplier
|
||||
* @param Societe $company Object third party for filter
|
||||
* @param User $user Filtre sur un user auteur des remises
|
||||
* @param string $filter Filtre autre
|
||||
* @param int $maxvalue Filter on max value for discount
|
||||
* @param int $discount_type 0 => customer discount, 1 => supplier discount
|
||||
* @return int <0 if KO, amount otherwise
|
||||
*/
|
||||
function getAvailableDiscounts($company='', $user='',$filter='', $maxvalue=0, $mode='customer')
|
||||
function getAvailableDiscounts($company='', $user='',$filter='', $maxvalue=0, $discount_type=0)
|
||||
{
|
||||
global $conf;
|
||||
|
||||
@ -359,8 +435,12 @@ class DiscountAbsolute
|
||||
//$sql = "SELECT rc.amount_ttc as amount";
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX."societe_remise_except as rc";
|
||||
$sql.= " WHERE rc.entity = " . $conf->entity;
|
||||
if ($mode != 'supplier') $sql.= " AND (rc.fk_facture IS NULL AND rc.fk_facture_line IS NULL)"; // Available
|
||||
else $sql.= " AND (rc.fk_suppler_invoice IS NULL AND rc.fk_supplier_invoice IS NULL)"; // Available
|
||||
$sql.= " AND rc.discount_type=".intval($discount_type);
|
||||
if (! empty($discount_type)) {
|
||||
$sql.= " AND (rc.fk_invoice_supplier IS NULL AND rc.fk_invoice_supplier_line IS NULL)"; // Available from supplier
|
||||
} else {
|
||||
$sql.= " AND (rc.fk_facture IS NULL AND rc.fk_facture_line IS NULL)"; // Available to customer
|
||||
}
|
||||
if (is_object($company)) $sql.= " AND rc.fk_soc = ".$company->id;
|
||||
if (is_object($user)) $sql.= " AND rc.fk_user = ".$user->id;
|
||||
if ($filter) $sql.=' AND ('.$filter.')';
|
||||
@ -452,7 +532,7 @@ class DiscountAbsolute
|
||||
$sql = 'SELECT sum(rc.amount_ttc) as amount, sum(rc.multicurrency_amount_ttc) as multicurrency_amount';
|
||||
$sql.= ' FROM '.MAIN_DB_PREFIX.'societe_remise_except as rc, '.MAIN_DB_PREFIX.'facture_fourn as f';
|
||||
$sql.= ' WHERE rc.fk_invoice_supplier_source=f.rowid AND rc.fk_invoice_supplier = '.$invoice->id;
|
||||
$sql.= ' AND (f.type = 2 OR f.type = 0)'; // Find discount coming from credit note or excess received
|
||||
$sql.= ' AND (f.type = 2 OR f.type = 0)'; // Find discount coming from credit note or excess paid
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -489,10 +569,12 @@ class DiscountAbsolute
|
||||
$result='';
|
||||
|
||||
if ($option == 'invoice') {
|
||||
$facid=! empty($this->discount_type)?$this->fk_invoice_supplier_source:$this->fk_facture_source;
|
||||
$link=! empty($this->discount_type)?'/fourn/facture/card.php':'/compta/facture/card.php';
|
||||
$label=$langs->trans("ShowDiscount").': '.$this->ref_facture_source;
|
||||
$link = '<a href="'.DOL_URL_ROOT.'/compta/facture/card.php?facid='.$this->fk_facture_source.'" title="'.dol_escape_htmltag($label, 1).'" class="classfortooltip">';
|
||||
$link = '<a href="'.DOL_URL_ROOT.$link.'?facid='.$facid.'" title="'.dol_escape_htmltag($label, 1).'" class="classfortooltip">';
|
||||
$linkend='</a>';
|
||||
$ref=$this->ref_facture_source;
|
||||
$ref=! empty($this->discount_type)?$this->ref_invoice_supplier_source:$this->ref_facture_source;
|
||||
$picto='bill';
|
||||
}
|
||||
if ($option == 'discount') {
|
||||
|
||||
@ -1236,6 +1236,7 @@ class Form
|
||||
if (preg_match('/\(CREDIT_NOTE\)/', $desc)) $desc=preg_replace('/\(CREDIT_NOTE\)/', $langs->trans("CreditNote"), $desc);
|
||||
if (preg_match('/\(DEPOSIT\)/', $desc)) $desc=preg_replace('/\(DEPOSIT\)/', $langs->trans("Deposit"), $desc);
|
||||
if (preg_match('/\(EXCESS RECEIVED\)/', $desc)) $desc=preg_replace('/\(EXCESS RECEIVED\)/', $langs->trans("ExcessReceived"), $desc);
|
||||
if (preg_match('/\(EXCESS PAID\)/', $desc)) $desc=preg_replace('/\(EXCESS PAID\)/', $langs->trans("ExcessPaid"), $desc);
|
||||
|
||||
$selectstring='';
|
||||
if ($selected > 0 && $selected == $obj->rowid) $selectstring=' selected';
|
||||
@ -2481,6 +2482,10 @@ class Form
|
||||
$opt = '<option value="'.$outkey.'"';
|
||||
if ($selected && $selected == $objp->idprodfournprice) $opt.= ' selected';
|
||||
if (empty($objp->idprodfournprice) && empty($alsoproductwithnosupplierprice)) $opt.=' disabled';
|
||||
if (!empty($objp->idprodfournprice) && $objp->idprodfournprice > 0)
|
||||
{
|
||||
$opt.= ' pbq="'.$objp->idprodfournprice.'" data-pbq="'.$objp->idprodfournprice.'" data-pbqqty="'.$objp->quantity.'" data-pbqpercent="'.$objp->remise_percent.'"';
|
||||
}
|
||||
$opt.= '>';
|
||||
|
||||
$objRef = $objp->ref;
|
||||
@ -4220,9 +4225,10 @@ class Form
|
||||
* @param int $maxvalue Max value for lines that can be selected
|
||||
* @param string $more More string to add
|
||||
* @param int $hidelist 1=Hide list
|
||||
* @param int $discount_type 0 => customer discount, 1 => supplier discount
|
||||
* @return void
|
||||
*/
|
||||
function form_remise_dispo($page, $selected, $htmlname, $socid, $amount, $filter='', $maxvalue=0, $more='', $hidelist=0)
|
||||
function form_remise_dispo($page, $selected, $htmlname, $socid, $amount, $filter='', $maxvalue=0, $more='', $hidelist=0, $discount_type=0)
|
||||
{
|
||||
global $conf,$langs;
|
||||
if ($htmlname != "none")
|
||||
@ -4231,28 +4237,51 @@ class Form
|
||||
print '<input type="hidden" name="action" value="setabsolutediscount">';
|
||||
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
|
||||
print '<div class="inline-block">';
|
||||
if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS))
|
||||
{
|
||||
if (! $filter || $filter=="fk_facture_source IS NULL") print $langs->trans("CompanyHasAbsoluteDiscount",price($amount,0,$langs,0,0,-1,$conf->currency)); // If we want deposit to be substracted to payments only and not to total of final invoice
|
||||
else print $langs->trans("CompanyHasCreditNote",price($amount,0,$langs,0,0,-1,$conf->currency));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (! $filter || $filter=="fk_facture_source IS NULL OR (fk_facture_source IS NOT NULL AND (description LIKE '(DEPOSIT)%' OR description LIKE '(EXCESS RECEIVED)%'))") print $langs->trans("CompanyHasAbsoluteDiscount",price($amount,0,$langs,0,0,-1,$conf->currency));
|
||||
else print $langs->trans("CompanyHasCreditNote",price($amount,0,$langs,0,0,-1,$conf->currency));
|
||||
if(! empty($discount_type)) {
|
||||
if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS))
|
||||
{
|
||||
if (! $filter || $filter=="fk_invoice_supplier_source IS NULL") $translationKey = 'HasAbsoluteDiscountFromSupplier'; // If we want deposit to be substracted to payments only and not to total of final invoice
|
||||
else $translationKey = 'HasCreditNoteFromSupplier';
|
||||
}
|
||||
else
|
||||
{
|
||||
if (! $filter || $filter=="fk_invoice_supplier_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS PAID)%')") $translationKey = 'HasAbsoluteDiscountFromSupplier';
|
||||
else $translationKey = 'HasCreditNoteFromSupplier';
|
||||
}
|
||||
} else {
|
||||
if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS))
|
||||
{
|
||||
if (! $filter || $filter=="fk_facture_source IS NULL") $translationKey = 'CompanyHasAbsoluteDiscount'; // If we want deposit to be substracted to payments only and not to total of final invoice
|
||||
else $translationKey = 'CompanyHasCreditNote';
|
||||
}
|
||||
else
|
||||
{
|
||||
if (! $filter || $filter=="fk_facture_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS RECEIVED)%')") $translationKey = 'CompanyHasAbsoluteDiscount';
|
||||
else $translationKey = 'CompanyHasCreditNote';
|
||||
}
|
||||
}
|
||||
print $langs->trans($translationKey,price($amount,0,$langs,0,0,-1,$conf->currency));
|
||||
if (empty($hidelist)) print ': ';
|
||||
print '</div>';
|
||||
if (empty($hidelist))
|
||||
{
|
||||
print '<div class="inline-block" style="padding-right: 10px">';
|
||||
$newfilter='fk_facture IS NULL AND fk_facture_line IS NULL'; // Remises disponibles
|
||||
$newfilter = 'discount_type='.intval($discount_type);
|
||||
if(! empty($discount_type)) {
|
||||
$newfilter.= ' AND fk_invoice_supplier IS NULL AND fk_invoice_supplier_line IS NULL'; // Supplier discounts available
|
||||
} else {
|
||||
$newfilter.= ' AND fk_facture IS NULL AND fk_facture_line IS NULL'; // Customer discounts available
|
||||
}
|
||||
if ($filter) $newfilter.=' AND ('.$filter.')';
|
||||
$nbqualifiedlines=$this->select_remises($selected,$htmlname,$newfilter,$socid,$maxvalue);
|
||||
if ($nbqualifiedlines > 0)
|
||||
{
|
||||
print ' <input type="submit" class="button" value="'.dol_escape_htmltag($langs->trans("UseLine")).'"';
|
||||
if ($filter && $filter != "fk_facture_source IS NULL OR (fk_facture_source IS NOT NULL AND description LIKE '(DEPOSIT)%')") print ' title="'.$langs->trans("UseCreditNoteInInvoicePayment").'"';
|
||||
if(! empty($discount_type) && $filter && $filter != "fk_invoice_supplier_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS PAID)%')")
|
||||
print ' title="'.$langs->trans("UseCreditNoteInInvoicePayment").'"';
|
||||
if(empty($discount_type) && $filter && $filter != "fk_facture_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS RECEIVED)%')")
|
||||
print ' title="'.$langs->trans("UseCreditNoteInInvoicePayment").'"';
|
||||
|
||||
print '>';
|
||||
}
|
||||
print '</div>';
|
||||
|
||||
@ -460,7 +460,7 @@ class Notify
|
||||
$message.= $outputlangs->transnoentities("YouReceiveMailBecauseOfNotification2",$application,$mysoc->name)."\n";
|
||||
$message.= "\n";
|
||||
$message.= $mesg;
|
||||
if ($link) $message=dol_concatdesc($message,$urlwithroot.$link);
|
||||
if ($link) $message.= "\n" . $urlwithroot . $link;
|
||||
|
||||
$parameters=array('notifcode'=>$notifcode, 'sendto'=>$sendto, 'replyto'=>$replyto, 'file'=>$file, 'mimefile'=>$mimefile, 'filename'=>$filename);
|
||||
$reshook=$hookmanager->executeHooks('formatNotificationMessage',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
|
||||
@ -555,77 +555,77 @@ class Notify
|
||||
|
||||
switch ($notifcode) {
|
||||
case 'BILL_VALIDATE':
|
||||
$link='/compta/facture/card.php?facid='.$object->id;
|
||||
$link = '<a href="' . $urlwithroot . '/compta/facture/card.php?facid=' . $object->id . '">' . $newref . '</a>';
|
||||
$dir_output = $conf->facture->dir_output;
|
||||
$object_type = 'facture';
|
||||
$mesg = $langs->transnoentitiesnoconv("EMailTextInvoiceValidated",$newref);
|
||||
$mesg = $langs->transnoentitiesnoconv("EMailTextInvoiceValidated",$link);
|
||||
break;
|
||||
case 'BILL_PAYED':
|
||||
$link='/compta/facture/card.php?facid='.$object->id;
|
||||
$link ='<a href="' . $urlwithroot . '/compta/facture/card.php?facid='.$object->id . '">' . $newref . '</a>';
|
||||
$dir_output = $conf->facture->dir_output;
|
||||
$object_type = 'facture';
|
||||
$mesg = $langs->transnoentitiesnoconv("EMailTextInvoicePayed",$newref);
|
||||
$mesg = $langs->transnoentitiesnoconv("EMailTextInvoicePayed",$link);
|
||||
break;
|
||||
case 'ORDER_VALIDATE':
|
||||
$link='/commande/card.php?id='.$object->id;
|
||||
$link = '<a href="' . $urlwithroot . '/commande/card.php?id='.$object->id . '">' . $newref . '</a>';
|
||||
$dir_output = $conf->commande->dir_output;
|
||||
$object_type = 'order';
|
||||
$mesg = $langs->transnoentitiesnoconv("EMailTextOrderValidated",$newref);
|
||||
$mesg = $langs->transnoentitiesnoconv("EMailTextOrderValidated",$link);
|
||||
break;
|
||||
case 'PROPAL_VALIDATE':
|
||||
$link='/comm/propal/card.php?id='.$object->id;
|
||||
$dir_output = $conf->propal->multidir_output[$object->entity];
|
||||
$object_type = 'propal';
|
||||
$mesg = $langs->transnoentitiesnoconv("EMailTextProposalValidated",$newref);
|
||||
$mesg = $langs->transnoentitiesnoconv("EMailTextProposalValidated",$link);
|
||||
break;
|
||||
case 'PROPAL_CLOSE_SIGNED':
|
||||
$link='/comm/propal/card.php?id='.$object->id;
|
||||
$dir_output = $conf->propal->multidir_output[$object->entity];
|
||||
$object_type = 'propal';
|
||||
$mesg = $langs->transnoentitiesnoconv("EMailTextProposalClosedSigned",$newref);
|
||||
$mesg = $langs->transnoentitiesnoconv("EMailTextProposalClosedSigned",$link);
|
||||
break;
|
||||
case 'FICHINTER_ADD_CONTACT':
|
||||
$link='/fichinter/card.php?id='.$object->id;
|
||||
$link = '<a href="' . $urlwithroot . '/fichinter/card.php?id='.$object->id . '">' . $newref . '</a>';
|
||||
$dir_output = $conf->facture->dir_output;
|
||||
$object_type = 'ficheinter';
|
||||
$mesg = $langs->transnoentitiesnoconv("EMailTextInterventionAddedContact",$newref);
|
||||
$mesg = $langs->transnoentitiesnoconv("EMailTextInterventionAddedContact",$link);
|
||||
break;
|
||||
case 'FICHINTER_VALIDATE':
|
||||
$link='/fichinter/card.php?id='.$object->id;
|
||||
$link = '<a href="' . $urlwithroot . '/fichinter/card.php?id='.$object->id . '">' . $newref . '</a>';
|
||||
$dir_output = $conf->facture->dir_output;
|
||||
$object_type = 'ficheinter';
|
||||
$mesg = $langs->transnoentitiesnoconv("EMailTextInterventionValidated",$newref);
|
||||
$mesg = $langs->transnoentitiesnoconv("EMailTextInterventionValidated",$link);
|
||||
break;
|
||||
case 'ORDER_SUPPLIER_VALIDATE':
|
||||
$link='/fourn/commande/card.php?id='.$object->id;
|
||||
$link = '<a href="' . $urlwithroot . '/fourn/commande/card.php?id='.$object->id . '">' . $newref . '</a>';
|
||||
$dir_output = $conf->fournisseur->commande->dir_output;
|
||||
$object_type = 'order_supplier';
|
||||
$mesg = $langs->transnoentitiesnoconv("Hello").",\n\n";
|
||||
$mesg.= $langs->transnoentitiesnoconv("EMailTextOrderValidatedBy",$newref,$user->getFullName($langs));
|
||||
$mesg.= $langs->transnoentitiesnoconv("EMailTextOrderValidatedBy",$link,$user->getFullName($langs));
|
||||
$mesg.= "\n\n".$langs->transnoentitiesnoconv("Sincerely").".\n\n";
|
||||
break;
|
||||
case 'ORDER_SUPPLIER_APPROVE':
|
||||
$link='/fourn/commande/card.php?id='.$object->id;
|
||||
$link = '<a href="' . $urlwithroot . '/fourn/commande/card.php?id='.$object->id . '">' . $newref . '</a>';
|
||||
$dir_output = $conf->fournisseur->commande->dir_output;
|
||||
$object_type = 'order_supplier';
|
||||
$mesg = $langs->transnoentitiesnoconv("Hello").",\n\n";
|
||||
$mesg.= $langs->transnoentitiesnoconv("EMailTextOrderApprovedBy",$newref,$user->getFullName($langs));
|
||||
$mesg.= $langs->transnoentitiesnoconv("EMailTextOrderApprovedBy",$link,$user->getFullName($langs));
|
||||
$mesg.= "\n\n".$langs->transnoentitiesnoconv("Sincerely").".\n\n";
|
||||
break;
|
||||
case 'ORDER_SUPPLIER_APPROVE2':
|
||||
$link='/fourn/commande/card.php?id='.$object->id;
|
||||
$link = '<a href="' . $urlwithroot . '/fourn/commande/card.php?id='.$object->id . '">' . $newref . '</a>';
|
||||
$dir_output = $conf->fournisseur->commande->dir_output;
|
||||
$object_type = 'order_supplier';
|
||||
$mesg = $langs->transnoentitiesnoconv("Hello").",\n\n";
|
||||
$mesg.= $langs->transnoentitiesnoconv("EMailTextOrderApprovedBy",$newref,$user->getFullName($langs));
|
||||
$mesg.= $langs->transnoentitiesnoconv("EMailTextOrderApprovedBy",$link,$user->getFullName($langs));
|
||||
$mesg.= "\n\n".$langs->transnoentitiesnoconv("Sincerely").".\n\n";
|
||||
break;
|
||||
case 'ORDER_SUPPLIER_REFUSE':
|
||||
$link='/fourn/commande/card.php?id='.$object->id;
|
||||
$link = '<a href="' . $urlwithroot . '/fourn/commande/card.php?id='.$object->id . '">' . $newref . '</a>';
|
||||
$dir_output = $conf->fournisseur->dir_output.'/commande/';
|
||||
$object_type = 'order_supplier';
|
||||
$mesg = $langs->transnoentitiesnoconv("Hello").",\n\n";
|
||||
$mesg.= $langs->transnoentitiesnoconv("EMailTextOrderRefusedBy",$newref,$user->getFullName($langs));
|
||||
$mesg.= $langs->transnoentitiesnoconv("EMailTextOrderRefusedBy",$link,$user->getFullName($langs));
|
||||
$mesg.= "\n\n".$langs->transnoentitiesnoconv("Sincerely").".\n\n";
|
||||
break;
|
||||
case 'SHIPPING_VALIDATE':
|
||||
@ -650,7 +650,7 @@ class Notify
|
||||
$message.= $langs->transnoentities("YouReceiveMailBecauseOfNotification2",$application,$mysoc->name)."\n";
|
||||
$message.= "\n";
|
||||
$message.= $mesg;
|
||||
if ($link) $message=dol_concatdesc($message,$urlwithroot.$link);
|
||||
$message = nl2br($message);
|
||||
|
||||
// Replace keyword __SUPERVISOREMAIL__
|
||||
if (preg_match('/__SUPERVISOREMAIL__/', $sendto))
|
||||
@ -678,7 +678,6 @@ class Notify
|
||||
if (! empty($hookmanager->resArray['subject'])) $subject.=$hookmanager->resArray['subject'];
|
||||
if (! empty($hookmanager->resArray['message'])) $message.=$hookmanager->resArray['message'];
|
||||
}
|
||||
|
||||
$mailfile = new CMailFile(
|
||||
$subject,
|
||||
$sendto,
|
||||
@ -690,7 +689,7 @@ class Notify
|
||||
'',
|
||||
'',
|
||||
0,
|
||||
-1
|
||||
1
|
||||
);
|
||||
|
||||
if ($mailfile->sendfile())
|
||||
|
||||
@ -93,7 +93,7 @@ class Utils
|
||||
// Define files log
|
||||
if ($dolibarr_main_data_root)
|
||||
{
|
||||
$filesarray=dol_dir_list($dolibarr_main_data_root, "files", 0, '.*\.log[\.0-9]*$', 'install\.lock$', 'name', SORT_ASC, 0, 0, '', 1);
|
||||
$filesarray=dol_dir_list($dolibarr_main_data_root, "files", 0, '.*\.log[\.0-9]*(\.gz)?$', 'install\.lock$', 'name', SORT_ASC, 0, 0, '', 1);
|
||||
}
|
||||
|
||||
$filelog='';
|
||||
@ -668,4 +668,112 @@ class Utils
|
||||
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This saves syslog files and compresses older ones
|
||||
* Used from cronjob
|
||||
*
|
||||
* @return int 0 if OK, < 0 if KO
|
||||
*/
|
||||
function compressSyslogs() {
|
||||
global $conf;
|
||||
|
||||
if(empty($conf->loghandlers['mod_syslog_file'])) { // File Syslog disabled
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(! function_exists('gzopen')) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
dol_include_once('/core/lib/files.lib.php');
|
||||
|
||||
$nbSaves = ! empty($conf->global->SYSLOG_FILE_SAVES) ? intval($conf->global->SYSLOG_FILE_SAVES) : 14;
|
||||
|
||||
if(empty($conf->global->SYSLOG_FILE)) {
|
||||
$mainlogdir = DOL_DATA_ROOT;
|
||||
$mainlog = 'dolibarr.log';
|
||||
} else {
|
||||
$mainlogfull = str_replace('DOL_DATA_ROOT', DOL_DATA_ROOT, $conf->global->SYSLOG_FILE);
|
||||
$mainlogdir = dirname($mainlogfull);
|
||||
$mainlog = basename($mainlogfull);
|
||||
}
|
||||
|
||||
$tabfiles = dol_dir_list(DOL_DATA_ROOT, 'files', 0, '^(dolibarr_.+|odt2pdf)\.log$'); // Also handle other log files like dolibarr_install.log
|
||||
$tabfiles[] = array('name' => $mainlog, 'path' => $mainlogdir);
|
||||
|
||||
foreach($tabfiles as $file) {
|
||||
|
||||
$logname = $file['name'];
|
||||
$logpath = $file['path'];
|
||||
|
||||
// Handle already compressed files
|
||||
|
||||
$filter = '^'.preg_quote($logname, '/').'\.([0-9]+)\.gz$';
|
||||
|
||||
$gzfilestmp = dol_dir_list($logpath, 'files', 0, $filter);
|
||||
$gzfiles = array();
|
||||
|
||||
foreach($gzfilestmp as $gzfile) {
|
||||
$tabmatches = array();
|
||||
preg_match('/'.$filter.'/i', $gzfile['name'], $tabmatches);
|
||||
|
||||
$numsave = intval($tabmatches[1]);
|
||||
|
||||
$gzfiles[$numsave] = $gzfile;
|
||||
}
|
||||
|
||||
krsort($gzfiles, SORT_NUMERIC);
|
||||
|
||||
foreach($gzfiles as $numsave => $dummy) {
|
||||
if(dol_is_file($logpath.'/'.$logname.'.'.($numsave+1).'.gz')) {
|
||||
return -2;
|
||||
}
|
||||
|
||||
if($numsave >= $nbSaves) {
|
||||
dol_delete_file($logpath.'/'.$logname.'.'.$numsave.'.gz');
|
||||
} else {
|
||||
dol_move($logpath.'/'.$logname.'.'.$numsave.'.gz', $logpath.'/'.$logname.'.'.($numsave+1).'.gz', 0, 1, 0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
// Compress last save
|
||||
|
||||
if(dol_is_file($logpath.'/'.$logname.'.1')) {
|
||||
if($nbSaves > 1) {
|
||||
$gzfilehandle = gzopen($logpath.'/'.$logname.'.2.gz', 'wb9');
|
||||
|
||||
if(empty($gzfilehandle)) {
|
||||
return -3;
|
||||
}
|
||||
|
||||
$sourcehandle = fopen($logpath.'/'.$logname.'.1', 'r');
|
||||
|
||||
if(empty($sourcehandle)) {
|
||||
return -4;
|
||||
}
|
||||
|
||||
while(! feof($sourcehandle)) {
|
||||
gzwrite($gzfilehandle, fread($sourcehandle, 512 * 1024)); // Read 512 kB at a time
|
||||
}
|
||||
|
||||
fclose($sourcehandle);
|
||||
gzclose($gzfilehandle);
|
||||
} else {
|
||||
dol_delete_file($logpath.'/'.$logname.'.1');
|
||||
}
|
||||
}
|
||||
|
||||
// Compress current file et recreate it
|
||||
|
||||
if(dol_is_file($logpath.'/'.$logname)) {
|
||||
if(dol_move($logpath.'/'.$logname, $logpath.'/'.$logname.'.1', 0, 1, 0, 0)) {
|
||||
$newlog = fopen($logpath.'/'.$logname, 'a+');
|
||||
fclose($newlog);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@ -73,13 +73,15 @@ function doc_getlinedesc($line,$outputlangs,$hideref=0,$hidedesc=0,$issupplierli
|
||||
{
|
||||
$discount=new DiscountAbsolute($db);
|
||||
$discount->fetch($line->fk_remise_except);
|
||||
$libelleproduitservice=$outputlangs->transnoentitiesnoconv("DiscountFromCreditNote",$discount->ref_facture_source);
|
||||
$sourceref=!empty($discount->discount_type)?$discount->ref_invoive_supplier_source:$discount->ref_facture_source;
|
||||
$libelleproduitservice=$outputlangs->transnoentitiesnoconv("DiscountFromCreditNote",$sourceref);
|
||||
}
|
||||
elseif ($desc == '(DEPOSIT)' && $line->fk_remise_except)
|
||||
{
|
||||
$discount=new DiscountAbsolute($db);
|
||||
$discount->fetch($line->fk_remise_except);
|
||||
$libelleproduitservice=$outputlangs->transnoentitiesnoconv("DiscountFromDeposit",$discount->ref_facture_source);
|
||||
$sourceref=!empty($discount->discount_type)?$discount->ref_invoive_supplier_source:$discount->ref_facture_source;
|
||||
$libelleproduitservice=$outputlangs->transnoentitiesnoconv("DiscountFromDeposit",$sourceref);
|
||||
// Add date of deposit
|
||||
if (! empty($conf->global->INVOICE_ADD_DEPOSIT_DATE)) $libelleproduitservice.=' ('.dol_print_date($discount->datec,'day','',$outputlangs).')';
|
||||
}
|
||||
@ -89,6 +91,12 @@ function doc_getlinedesc($line,$outputlangs,$hideref=0,$hidedesc=0,$issupplierli
|
||||
$discount->fetch($line->fk_remise_except);
|
||||
$libelleproduitservice=$outputlangs->transnoentitiesnoconv("DiscountFromExcessReceived",$discount->ref_facture_source);
|
||||
}
|
||||
elseif ($desc == '(EXCESS PAID)' && $line->fk_remise_except)
|
||||
{
|
||||
$discount=new DiscountAbsolute($db);
|
||||
$discount->fetch($line->fk_remise_except);
|
||||
$libelleproduitservice=$outputlangs->transnoentitiesnoconv("DiscountFromExcessPaid",$discount->ref_invoice_supplier_source);
|
||||
}
|
||||
else
|
||||
{
|
||||
if ($idprod)
|
||||
|
||||
@ -297,16 +297,32 @@ function dol_dir_list_in_database($path, $filter="", $excludefilter=null, $sortc
|
||||
* Complete $filearray with data from database.
|
||||
* This will call doldir_list_indatabase to complate filearray.
|
||||
*
|
||||
* @param array $filearray Array of files get using dol_dir_list
|
||||
* @param array $filearray Array of files get using dol_dir_list
|
||||
* @param string $relativedir Relative dir from DOL_DATA_ROOT
|
||||
* @return void
|
||||
*/
|
||||
function completeFileArrayWithDatabaseInfo(&$filearray, $relativedir)
|
||||
{
|
||||
global $db, $user;
|
||||
global $conf, $db, $user;
|
||||
|
||||
$filearrayindatabase = dol_dir_list_in_database($relativedir, '', null, 'name', SORT_ASC);
|
||||
|
||||
// TODO Remove this when PRODUCT_USE_OLD_PATH_FOR_PHOTO will be removed
|
||||
global $modulepart;
|
||||
if ($modulepart == 'produit' && ! empty($conf->global->PRODUCT_USE_OLD_PATH_FOR_PHOTO)) {
|
||||
global $object;
|
||||
if (! empty($object->id))
|
||||
{
|
||||
if (! empty($conf->product->enabled)) $upload_dirold = $conf->product->multidir_output[$object->entity].'/'.substr(substr("000".$object->id, -2),1,1).'/'.substr(substr("000".$object->id, -2),0,1).'/'.$object->id."/photos";
|
||||
else $upload_dirold = $conf->service->multidir_output[$object->entity].'/'.substr(substr("000".$object->id, -2),1,1).'/'.substr(substr("000".$object->id, -2),0,1).'/'.$object->id."/photos";
|
||||
|
||||
$relativedirold = preg_replace('/^'.preg_quote(DOL_DATA_ROOT,'/').'/', '', $upload_dirold);
|
||||
$relativedirold = preg_replace('/^[\\/]/','',$relativedirold);
|
||||
|
||||
$filearrayindatabase = array_merge($filearrayindatabase, dol_dir_list_in_database($relativedirold, '', null, 'name', SORT_ASC));
|
||||
}
|
||||
}
|
||||
|
||||
//var_dump($filearray);
|
||||
//var_dump($filearrayindatabase);
|
||||
|
||||
|
||||
@ -34,7 +34,7 @@
|
||||
function facturefourn_prepare_head($object)
|
||||
{
|
||||
global $db, $langs, $conf;
|
||||
|
||||
|
||||
$h = 0;
|
||||
$head = array();
|
||||
|
||||
@ -102,7 +102,7 @@ function facturefourn_prepare_head($object)
|
||||
function ordersupplier_prepare_head($object)
|
||||
{
|
||||
global $db, $langs, $conf, $user;
|
||||
|
||||
|
||||
$h = 0;
|
||||
$head = array();
|
||||
|
||||
@ -111,15 +111,6 @@ function ordersupplier_prepare_head($object)
|
||||
$head[$h][2] = 'card';
|
||||
$h++;
|
||||
|
||||
if (! empty($conf->stock->enabled) && ! empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER))
|
||||
{
|
||||
$langs->load("stocks");
|
||||
$head[$h][0] = DOL_URL_ROOT.'/fourn/commande/dispatch.php?id='.$object->id;
|
||||
$head[$h][1] = $langs->trans("OrderDispatch");
|
||||
$head[$h][2] = 'dispatch';
|
||||
$h++;
|
||||
}
|
||||
|
||||
if (empty($conf->global->MAIN_DISABLE_CONTACTS_TAB))
|
||||
{
|
||||
$nbContact = count($object->liste_contact(-1,'internal')) + count($object->liste_contact(-1,'external'));
|
||||
@ -130,7 +121,16 @@ function ordersupplier_prepare_head($object)
|
||||
$h++;
|
||||
}
|
||||
|
||||
// Show more tabs from modules
|
||||
if (! empty($conf->stock->enabled) && ! empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER))
|
||||
{
|
||||
$langs->load("stocks");
|
||||
$head[$h][0] = DOL_URL_ROOT.'/fourn/commande/dispatch.php?id='.$object->id;
|
||||
$head[$h][1] = $langs->trans("OrderDispatch");
|
||||
$head[$h][2] = 'dispatch';
|
||||
$h++;
|
||||
}
|
||||
|
||||
// Show more tabs from modules
|
||||
// Entries must be declared in modules descriptor with line
|
||||
// $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
|
||||
// $this->tabs = array('entity:-tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to remove a tab
|
||||
@ -193,7 +193,7 @@ function supplierorder_admin_prepare_head()
|
||||
$head[$h][1] = $langs->trans("SuppliersInvoice");
|
||||
$head[$h][2] = 'invoice';
|
||||
$h++;
|
||||
|
||||
|
||||
$head[$h][0] = DOL_URL_ROOT."/admin/supplier_payment.php";
|
||||
$head[$h][1] = $langs->trans("SuppliersPayment");
|
||||
$head[$h][2] = 'supplierpayment';
|
||||
|
||||
@ -1221,7 +1221,7 @@ function dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $pi
|
||||
|
||||
$tabsname=str_replace("@", "", $picto);
|
||||
$out.='<div id="moretabs'.$tabsname.'" class="inline-block tabsElem">';
|
||||
$out.='<a href="#" class="tab moretab inline-block tabunactive">'.$langs->trans("More").'... ('.$nbintab.')</a>';
|
||||
$out.='<a href="#" class="tab moretab inline-block tabunactive reposition">'.$langs->trans("More").'... ('.$nbintab.')</a>';
|
||||
$out.='<div id="moretabsList'.$tabsname.'" style="position: absolute; '.$left.': -999em; text-align: '.$left.'; margin:0px; padding:2px">';
|
||||
$out.=$outmore;
|
||||
$out.='</div>';
|
||||
@ -3989,7 +3989,7 @@ function load_fiche_titre($titre, $morehtmlright='', $picto='title_generic.png',
|
||||
}
|
||||
if (dol_strlen($morehtmlright))
|
||||
{
|
||||
$return.= '<td class="nobordernopadding titre_right" align="right" valign="middle">'.$morehtmlright.'</td>';
|
||||
$return.= '<td class="nobordernopadding titre_right wordbreak" align="right" valign="middle">'.$morehtmlright.'</td>';
|
||||
}
|
||||
$return.= '</tr></table>'."\n";
|
||||
|
||||
|
||||
@ -715,9 +715,12 @@ function get_next_value($db,$mask,$table,$field,$where='',$objsoc='',$date='',$m
|
||||
global $conf,$user;
|
||||
|
||||
if (! is_object($objsoc)) $valueforccc=$objsoc;
|
||||
else if($table == "commande_fournisseur" || $table == "facture_fourn" ) $valueforccc=$objsoc->code_fournisseur;
|
||||
else if ($table == "commande_fournisseur" || $table == "facture_fourn" ) $valueforccc=$objsoc->code_fournisseur;
|
||||
else $valueforccc=$objsoc->code_client;
|
||||
|
||||
$sharetable = $table;
|
||||
if ($table == 'facture' || $table == 'invoice') $sharetable = 'invoicenumber'; // for getEntity function
|
||||
|
||||
// Clean parameters
|
||||
if ($date == '') $date=dol_now(); // We use local year and month of PHP server to search numbers
|
||||
// but we should use local year and month of user
|
||||
@ -979,7 +982,7 @@ function get_next_value($db,$mask,$table,$field,$where='',$objsoc='',$date='',$m
|
||||
$sql.= " WHERE ".$field." LIKE '".$maskLike."'";
|
||||
$sql.= " AND ".$field." NOT LIKE '(PROV%)'";
|
||||
if ($bentityon) // only if entity enable
|
||||
$sql.= " AND entity IN (".getEntity($table, 1).")";
|
||||
$sql.= " AND entity IN (".getEntity($sharetable).")";
|
||||
|
||||
if ($where) $sql.=$where;
|
||||
if ($sqlwhere) $sql.=' AND '.$sqlwhere;
|
||||
@ -1027,7 +1030,7 @@ function get_next_value($db,$mask,$table,$field,$where='',$objsoc='',$date='',$m
|
||||
$sql.= " WHERE ".$field." LIKE '".$maskLike."'";
|
||||
$sql.= " AND ".$field." NOT LIKE '%PROV%'";
|
||||
if ($bentityon) // only if entity enable
|
||||
$sql.= " AND entity IN (".getEntity($table, 1).")";
|
||||
$sql.= " AND entity IN (".getEntity($sharetable).")";
|
||||
if ($where) $sql.=$where;
|
||||
if ($sqlwhere) $sql.=' AND '.$sqlwhere;
|
||||
|
||||
@ -1081,7 +1084,7 @@ function get_next_value($db,$mask,$table,$field,$where='',$objsoc='',$date='',$m
|
||||
//$sql.= " WHERE ".$field." not like '(%'";
|
||||
$maskrefclient_sql.= " WHERE ".$field." LIKE '".$maskrefclient_maskLike."'";
|
||||
if ($bentityon) // only if entity enable
|
||||
$maskrefclient_sql.= " AND entity IN (".getEntity($table, 1).")";
|
||||
$maskrefclient_sql.= " AND entity IN (".getEntity($sharetable).")";
|
||||
if ($where) $maskrefclient_sql.=$where; //use the same optional where as general mask
|
||||
if ($sqlwhere) $maskrefclient_sql.=' AND '.$sqlwhere; //use the same sqlwhere as general mask
|
||||
$maskrefclient_sql.=' AND (SUBSTRING('.$field.', '.(strpos($maskwithnocode,$maskrefclient)+1).', '.dol_strlen($maskrefclient_maskclientcode).")='".$maskrefclient_clientcode."')";
|
||||
|
||||
@ -27,12 +27,15 @@
|
||||
$supportedoauth2array=array(
|
||||
'OAUTH_GOOGLE_NAME'=>'google',
|
||||
);
|
||||
|
||||
if ($conf->global->MAIN_FEATURES_LEVEL >= 2)
|
||||
{
|
||||
$supportedoauth2array['OAUTH_GITHUB_NAME']='github';
|
||||
$supportedoauth2array['OAUTH_STRIPE_TEST_NAME']='stripetest';
|
||||
$supportedoauth2array['OAUTH_STRIPE_LIVE_NAME']='stripelive';
|
||||
}
|
||||
$supportedoauth2array['OAUTH_GITHUB_NAME']='github';
|
||||
|
||||
|
||||
|
||||
// API access parameters OAUTH
|
||||
$list = array (
|
||||
array(
|
||||
@ -217,7 +220,17 @@ $list = array (
|
||||
'OAUTH_STRAVA_ID',
|
||||
'OAUTH_STRAVA_SECRET',
|
||||
),
|
||||
array(
|
||||
array(
|
||||
'OAUTH_STRIPE_TEST_NAME',
|
||||
'OAUTH_STRIPE_TEST_ID',
|
||||
'STRIPE_TEST_SECRET_KEY',
|
||||
),
|
||||
array(
|
||||
'OAUTH_STRIPE_LIVE_NAME',
|
||||
'OAUTH_STRIPE_LIVE_ID',
|
||||
'STRIPE_LIVE_SECRET_KEY',
|
||||
),
|
||||
array(
|
||||
'OAUTH_TUMBLR_NAME',
|
||||
'OAUTH_TUMBLR_ID',
|
||||
'OAUTH_TUMBLR_SECRET',
|
||||
@ -266,12 +279,12 @@ function oauthadmin_prepare_head()
|
||||
$head[$h][1] = $langs->trans("OAuthServices");
|
||||
$head[$h][2] = 'services';
|
||||
$h++;
|
||||
|
||||
|
||||
$head[$h][0] = dol_buildpath('/admin/oauthlogintokens.php', 1);
|
||||
$head[$h][1] = $langs->trans("TokenManager");
|
||||
$head[$h][2] = 'tokengeneration';
|
||||
$h++;
|
||||
|
||||
|
||||
complete_head_from_modules($conf, $langs, null, $head, $h, 'oauthadmin');
|
||||
|
||||
complete_head_from_modules($conf, $langs, null, $head, $h, 'oauthadmin', 'remove');
|
||||
|
||||
@ -1236,13 +1236,15 @@ function pdf_getlinedesc($object,$i,$outputlangs,$hideref=0,$hidedesc=0,$issuppl
|
||||
{
|
||||
$discount=new DiscountAbsolute($db);
|
||||
$discount->fetch($object->lines[$i]->fk_remise_except);
|
||||
$libelleproduitservice=$outputlangs->transnoentitiesnoconv("DiscountFromCreditNote",$discount->ref_facture_source);
|
||||
$sourceref=!empty($discount->discount_type)?$discount->ref_invoive_supplier_source:$discount->ref_facture_source;
|
||||
$libelleproduitservice=$outputlangs->transnoentitiesnoconv("DiscountFromCreditNote",$sourceref);
|
||||
}
|
||||
elseif ($desc == '(DEPOSIT)' && $object->lines[$i]->fk_remise_except)
|
||||
{
|
||||
$discount=new DiscountAbsolute($db);
|
||||
$discount->fetch($object->lines[$i]->fk_remise_except);
|
||||
$libelleproduitservice=$outputlangs->transnoentitiesnoconv("DiscountFromDeposit",$discount->ref_facture_source);
|
||||
$sourceref=!empty($discount->discount_type)?$discount->ref_invoive_supplier_source:$discount->ref_facture_source;
|
||||
$libelleproduitservice=$outputlangs->transnoentitiesnoconv("DiscountFromDeposit",$sourceref);
|
||||
// Add date of deposit
|
||||
if (! empty($conf->global->INVOICE_ADD_DEPOSIT_DATE)) echo ' ('.dol_print_date($discount->datec,'day','',$outputlangs).')';
|
||||
}
|
||||
@ -1252,6 +1254,12 @@ function pdf_getlinedesc($object,$i,$outputlangs,$hideref=0,$hidedesc=0,$issuppl
|
||||
$discount->fetch($object->lines[$i]->fk_remise_except);
|
||||
$libelleproduitservice=$outputlangs->transnoentitiesnoconv("DiscountFromExcessReceived",$discount->ref_facture_source);
|
||||
}
|
||||
elseif ($desc == '(EXCESS PAID)' && $object->lines[$i]->fk_remise_except)
|
||||
{
|
||||
$discount=new DiscountAbsolute($db);
|
||||
$discount->fetch($object->lines[$i]->fk_remise_except);
|
||||
$libelleproduitservice=$outputlangs->transnoentitiesnoconv("DiscountFromExcessPaid",$discount->ref_invoice_supplier_source);
|
||||
}
|
||||
else
|
||||
{
|
||||
if ($idprod)
|
||||
|
||||
@ -153,7 +153,7 @@ class mod_facture_mars extends ModeleNumRefFactures
|
||||
$sql = "SELECT MAX(CAST(SUBSTRING(facnumber FROM ".$posindice.") AS SIGNED)) as max"; // This is standard SQL
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX."facture";
|
||||
$sql.= " WHERE facnumber LIKE '".$prefix."____-%'";
|
||||
$sql.= " AND entity IN (".getEntity('facture').")";
|
||||
$sql.= " AND entity IN (".getEntity('invoicenumber').")";
|
||||
|
||||
$resql=$db->query($sql);
|
||||
dol_syslog(get_class($this)."::getNextValue", LOG_DEBUG);
|
||||
@ -177,7 +177,7 @@ class mod_facture_mars extends ModeleNumRefFactures
|
||||
$sql = "SELECT facnumber as ref";
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX."facture";
|
||||
$sql.= " WHERE facnumber LIKE '".$prefix."____-".$num."'";
|
||||
$sql.= " AND entity IN (".getEntity('facture').")";
|
||||
$sql.= " AND entity IN (".getEntity('invoicenumber').")";
|
||||
|
||||
dol_syslog(get_class($this)."::getNextValue", LOG_DEBUG);
|
||||
$resql=$db->query($sql);
|
||||
|
||||
@ -169,7 +169,7 @@ class mod_facture_terre extends ModeleNumRefFactures
|
||||
$sql = "SELECT MAX(CAST(SUBSTRING(facnumber FROM ".$posindice.") AS SIGNED)) as max"; // This is standard SQL
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX."facture";
|
||||
$sql.= " WHERE facnumber LIKE '".$prefix."____-%'";
|
||||
$sql.= " AND entity IN (".getEntity('facture').")";
|
||||
$sql.= " AND entity IN (".getEntity('invoicenumber').")";
|
||||
|
||||
$resql=$db->query($sql);
|
||||
dol_syslog(get_class($this)."::getNextValue", LOG_DEBUG);
|
||||
@ -193,7 +193,7 @@ class mod_facture_terre extends ModeleNumRefFactures
|
||||
$sql = "SELECT facnumber as ref";
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX."facture";
|
||||
$sql.= " WHERE facnumber LIKE '".$prefix."____-".$num."'";
|
||||
$sql.= " AND entity IN (".getEntity('facture').")";
|
||||
$sql.= " AND entity IN (".getEntity('invoicenumber').")";
|
||||
|
||||
dol_syslog(get_class($this)."::getNextValue", LOG_DEBUG);
|
||||
$resql=$db->query($sql);
|
||||
|
||||
@ -1,7 +1,8 @@
|
||||
<?php
|
||||
/* Copyright (C) 2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
|
||||
* Copyright (C) 2004-2012 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||
* Copyright (C) 2015 Jean-François Ferry <jfefe@aternatik.fr>
|
||||
/* Copyright (C) 2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
|
||||
* Copyright (C) 2004-2012 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||
* Copyright (C) 2015 Jean-François Ferry <jfefe@aternatik.fr>
|
||||
* Copyright (C) 2018 Regis Houssin <regis.houssin@inodbox.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@ -60,12 +61,13 @@ class modApi extends DolibarrModules
|
||||
$this->version = 'dolibarr';
|
||||
// Key used in llx_const table to save module status enabled/disabled (where MYMODULE is value of property name of module in uppercase)
|
||||
$this->const_name = 'MAIN_MODULE_'.strtoupper($this->name);
|
||||
// Can be enabled / disabled only in the main company with superadmin account
|
||||
$this->core_enabled = 1;
|
||||
// Name of image file used for this module.
|
||||
// If file is in theme/yourtheme/img directory under name object_pictovalue.png, use this->picto='pictovalue'
|
||||
// If file is in module/img directory under name object_pictovalue.png, use this->picto='pictovalue@module'
|
||||
$this->picto='technic';
|
||||
|
||||
|
||||
$this->module_parts = array();
|
||||
|
||||
// Data directories to create when module is enabled.
|
||||
@ -230,5 +232,24 @@ class modApi extends DolibarrModules
|
||||
|
||||
return $this->_init($sql, $options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Function called when module is disabled.
|
||||
* Remove from database constants, boxes and permissions from Dolibarr database.
|
||||
* Data directories are not deleted.
|
||||
*
|
||||
* @param string $options Options when enabling module ('', 'noboxes')
|
||||
* @return int 1 if OK, 0 if KO
|
||||
*/
|
||||
function remove($options = '')
|
||||
{
|
||||
// Remove old constants with entity fields different of 0
|
||||
$sql = array(
|
||||
"DELETE FROM ".MAIN_DB_PREFIX."const WHERE name = ".$this->db->encrypt('MAIN_MODULE_API', 1),
|
||||
"DELETE FROM ".MAIN_DB_PREFIX."const WHERE name = ".$this->db->encrypt('API_PRODUCTION_MODE', 1)
|
||||
);
|
||||
|
||||
return $this->_remove($sql, $options);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -128,13 +128,7 @@ class modStock extends DolibarrModules
|
||||
$this->rights[6][1] = 'inventoryCreatePermission'; // Permission label
|
||||
$this->rights[6][3] = 0; // Permission by default for new user (0/1)
|
||||
$this->rights[6][4] = 'advance_inventory'; // In php code, permission will be checked by test if ($user->rights->permkey->level1->level2)
|
||||
$this->rights[6][5] = 'create'; // In php code, permission will be checked by test if ($user->rights->permkey->level1->level2)
|
||||
|
||||
$this->rights[7][0] = 1013;
|
||||
$this->rights[7][1] = 'inventoryWritePermission'; // Permission label
|
||||
$this->rights[7][3] = 0; // Permission by default for new user (0/1)
|
||||
$this->rights[7][4] = 'advance_inventory'; // In php code, permission will be checked by test if ($user->rights->permkey->level1->level2)
|
||||
$this->rights[7][5] = 'write'; // In php code, permission will be checked by test if ($user->rights->permkey->level1->level2)
|
||||
$this->rights[6][5] = 'write'; // In php code, permission will be checked by test if ($user->rights->permkey->level1->level2)
|
||||
|
||||
$this->rights[8][0] = 1014;
|
||||
$this->rights[8][1] = 'inventoryValidatePermission'; // Permission label
|
||||
|
||||
@ -79,5 +79,10 @@ class modSyslog extends DolibarrModules
|
||||
// Permissions
|
||||
$this->rights = array();
|
||||
$this->rights_class = 'syslog';
|
||||
|
||||
// Cronjobs
|
||||
$this->cronjobs = array(
|
||||
0=>array('label'=>'CompressSyslogs', 'jobtype'=>'method', 'class'=>'core/class/utils.class.php', 'objectname'=>'Utils', 'method'=>'compressSyslogs', 'parameters'=>'', 'comment'=>'PurgeDeleteTemporaryFiles', 'frequency'=>1, 'unitfrequency'=> 3600 * 24, 'priority'=>50, 'status'=>0, 'test'=>true),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@ -109,7 +109,7 @@ if (! empty($_GET['code'])) // We are coming from oauth provider page
|
||||
// We should have
|
||||
//$_GET=array('code' => string 'aaaaaaaaaaaaaa' (length=20), 'state' => string 'user,public_repo' (length=16))
|
||||
|
||||
dol_syslog("We are coming fr mthe oauth provider page");
|
||||
dol_syslog("We are coming from the oauth provider page");
|
||||
//llxHeader('',$langs->trans("OAuthSetup"));
|
||||
|
||||
//$linkback='<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
|
||||
@ -125,14 +125,14 @@ if (! empty($_GET['code'])) // We are coming from oauth provider page
|
||||
//var_dump($_GET['code']);
|
||||
//var_dump($state);
|
||||
//var_dump($apiService); // OAuth\OAuth2\Service\GitHub
|
||||
|
||||
|
||||
//$token = $apiService->requestAccessToken($_GET['code'], $state);
|
||||
$token = $apiService->requestAccessToken($_GET['code']);
|
||||
// Github is a service that does not need state to be stored.
|
||||
// Into constructor of GitHub, the call
|
||||
// parent::__construct($credentials, $httpClient, $storage, $scopes, $baseApiUri)
|
||||
// has not the ending parameter to true like the Google class constructor.
|
||||
|
||||
|
||||
setEventMessages($langs->trans('NewTokenStored'), null, 'mesgs'); // Stored into object managed by class DoliStorage so into table oauth_token
|
||||
|
||||
$backtourl = $_SESSION["backtourlsavedbeforeoauthjump"];
|
||||
|
||||
@ -109,7 +109,7 @@ if ($action == 'delete')
|
||||
|
||||
if (! empty($_GET['code'])) // We are coming from oauth provider page
|
||||
{
|
||||
dol_syslog("We are coming fr mthe oauth provider page");
|
||||
dol_syslog("We are coming from the oauth provider page");
|
||||
//llxHeader('',$langs->trans("OAuthSetup"));
|
||||
|
||||
//$linkback='<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
|
||||
|
||||
180
htdocs/core/modules/oauth/stripetest_oauthcallback.php
Normal file
180
htdocs/core/modules/oauth/stripetest_oauthcallback.php
Normal file
@ -0,0 +1,180 @@
|
||||
<?php
|
||||
/*
|
||||
* Copyright (C) 2015 Frederic France <frederic.france@free.fr>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file htdocs/core/modules/oauth/stripe_oauthcallback.php
|
||||
* \ingroup oauth
|
||||
* \brief Page to get oauth callback
|
||||
*/
|
||||
|
||||
require '../../../main.inc.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/includes/OAuth/bootstrap.php';
|
||||
use OAuth\Common\Storage\DoliStorage;
|
||||
use OAuth\Common\Consumer\Credentials;
|
||||
use OAuth\OAuth2\Service\GitHub;
|
||||
|
||||
// Define $urlwithroot
|
||||
$urlwithouturlroot=preg_replace('/'.preg_quote(DOL_URL_ROOT,'/').'$/i','',trim($dolibarr_main_url_root));
|
||||
$urlwithroot=$urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file
|
||||
//$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current
|
||||
|
||||
|
||||
|
||||
$action = GETPOST('action', 'alpha');
|
||||
$backtourl = GETPOST('backtourl', 'alpha');
|
||||
|
||||
|
||||
/**
|
||||
* Create a new instance of the URI class with the current URI, stripping the query string
|
||||
*/
|
||||
$uriFactory = new \OAuth\Common\Http\Uri\UriFactory();
|
||||
//$currentUri = $uriFactory->createFromSuperGlobalArray($_SERVER);
|
||||
//$currentUri->setQuery('');
|
||||
$currentUri = $uriFactory->createFromAbsolute($urlwithroot.'/core/modules/oauth/stripe_oauthcallback.php');
|
||||
|
||||
|
||||
/**
|
||||
* Load the credential for the service
|
||||
*/
|
||||
|
||||
/** @var $serviceFactory \OAuth\ServiceFactory An OAuth service factory. */
|
||||
$serviceFactory = new \OAuth\ServiceFactory();
|
||||
$httpClient = new \OAuth\Common\Http\Client\CurlClient();
|
||||
// TODO Set options for proxy and timeout
|
||||
// $params=array('CURLXXX'=>value, ...)
|
||||
//$httpClient->setCurlParameters($params);
|
||||
$serviceFactory->setHttpClient($httpClient);
|
||||
|
||||
// Dolibarr storage
|
||||
$storage = new DoliStorage($db, $conf);
|
||||
|
||||
// Setup the credentials for the requests
|
||||
$credentials = new Credentials(
|
||||
$conf->global->OAUTH_STRIPE_TEST_ID,
|
||||
$conf->global->STRIPE_TEST_SECRET_KEY,
|
||||
$currentUri->getAbsoluteUri()
|
||||
);
|
||||
|
||||
$requestedpermissionsarray=array();
|
||||
if (GETPOST('state')) $requestedpermissionsarray=explode(',', GETPOST('state')); // Example: 'userinfo_email,userinfo_profile,cloud_print'. 'state' parameter is standard to retrieve some parameters back
|
||||
/*if ($action != 'delete' && empty($requestedpermissionsarray))
|
||||
{
|
||||
print 'Error, parameter state is not defined';
|
||||
exit;
|
||||
}*/
|
||||
//var_dump($requestedpermissionsarray);exit;
|
||||
|
||||
// Instantiate the Api service using the credentials, http client and storage mechanism for the token
|
||||
/** @var $apiService Service */
|
||||
//$apiService = $serviceFactory->createService('StripeTest', $credentials, $storage, $requestedpermissionsarray);
|
||||
|
||||
$sql="INSERT INTO ".MAIN_DB_PREFIX."oauth_token set service='StripeTest', entity=".$conf->entity;
|
||||
$db->query($sql);
|
||||
|
||||
// access type needed to have oauth provider refreshing token
|
||||
//$apiService->setAccessType('offline');
|
||||
|
||||
$langs->load("oauth");
|
||||
|
||||
|
||||
/*
|
||||
* Actions
|
||||
*/
|
||||
|
||||
|
||||
if ($action == 'delete')
|
||||
{
|
||||
$storage->clearToken('StripeTest');
|
||||
|
||||
setEventMessages($langs->trans('TokenDeleted'), null, 'mesgs');
|
||||
|
||||
header('Location: ' . $backtourl);
|
||||
exit();
|
||||
}
|
||||
|
||||
if (! empty($_GET['code'])) // We are coming from oauth provider page
|
||||
{
|
||||
// We should have
|
||||
//$_GET=array('code' => string 'aaaaaaaaaaaaaa' (length=20), 'state' => string 'user,public_repo' (length=16))
|
||||
|
||||
dol_syslog("We are coming from the oauth provider page");
|
||||
//llxHeader('',$langs->trans("OAuthSetup"));
|
||||
|
||||
//$linkback='<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
|
||||
//print load_fiche_titre($langs->trans("OAuthSetup"),$linkback,'title_setup');
|
||||
|
||||
//dol_fiche_head();
|
||||
// retrieve the CSRF state parameter
|
||||
$state = isset($_GET['state']) ? $_GET['state'] : null;
|
||||
//print '<table>';
|
||||
|
||||
// This was a callback request from service, get the token
|
||||
try {
|
||||
//var_dump($_GET['code']);
|
||||
//var_dump($state);
|
||||
//var_dump($apiService); // OAuth\OAuth2\Service\GitHub
|
||||
|
||||
//$token = $apiService->requestAccessToken($_GET['code'], $state);
|
||||
$token = $apiService->requestAccessToken($_GET['code']);
|
||||
// Github is a service that does not need state to be stored.
|
||||
// Into constructor of GitHub, the call
|
||||
// parent::__construct($credentials, $httpClient, $storage, $scopes, $baseApiUri)
|
||||
// has not the ending parameter to true like the Google class constructor.
|
||||
|
||||
setEventMessages($langs->trans('NewTokenStored'), null, 'mesgs'); // Stored into object managed by class DoliStorage so into table oauth_token
|
||||
|
||||
$backtourl = $_SESSION["backtourlsavedbeforeoauthjump"];
|
||||
unset($_SESSION["backtourlsavedbeforeoauthjump"]);
|
||||
|
||||
header('Location: ' . $backtourl);
|
||||
exit();
|
||||
} catch (Exception $e) {
|
||||
print $e->getMessage();
|
||||
}
|
||||
}
|
||||
else // If entry on page with no parameter, we arrive here
|
||||
{
|
||||
$_SESSION["backtourlsavedbeforeoauthjump"]=$backtourl;
|
||||
|
||||
// This may create record into oauth_state before the header redirect.
|
||||
// Creation of record with state in this tables depend on the Provider used (see its constructor).
|
||||
if (GETPOST('state'))
|
||||
{
|
||||
$url = $apiService->getAuthorizationUri(array('state'=>GETPOST('state')));
|
||||
}
|
||||
else
|
||||
{
|
||||
//$url = $apiService->getAuthorizationUri(); // Parameter state will be randomly generated
|
||||
//https://connect.stripe.com/oauth/authorize?response_type=code&client_id=ca_AX27ut70tJ1j6eyFCV3ObEXhNOo2jY6V&scope=read_write
|
||||
$url = 'https://connect.stripe.com/oauth/authorize?response_type=code&client_id='.$conf->global->OAUTH_STRIPE_TEST_ID.'&scope=read_write';
|
||||
}
|
||||
|
||||
// we go on oauth provider authorization page
|
||||
header('Location: ' . $url);
|
||||
exit();
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* View
|
||||
*/
|
||||
|
||||
// No view at all, just actions
|
||||
|
||||
$db->close();
|
||||
|
||||
@ -151,7 +151,7 @@ if (empty($reshook) && ! empty($extrafields->attributes[$object->table_element][
|
||||
jQuery(document).ready(function() {
|
||||
function showOptions(child_list, parent_list)
|
||||
{
|
||||
var val = $("select[name=\"options_"+parent_list+"\"]").val();
|
||||
var val = $("select[name="+parent_list+"]").val();
|
||||
var parentVal = parent_list + ":" + val;
|
||||
if(val > 0) {
|
||||
$("select[name=\""+child_list+"\"] option[parent]").hide();
|
||||
|
||||
104
htdocs/core/tpl/object_discounts.tpl.php
Normal file
104
htdocs/core/tpl/object_discounts.tpl.php
Normal file
@ -0,0 +1,104 @@
|
||||
<?php
|
||||
/* Copyright (C) 2018 ATM Consulting <support@atm-consulting.fr>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Needs the following variables defined:
|
||||
* $object Proposal, order, invoice (including supplier versions)
|
||||
* $thirdparty Thirdparty of object
|
||||
* $absolute_discount Amount of fixed discounts available
|
||||
* $absolute_creditnote Amount of credit notes available
|
||||
* $discount_type 0 => Customer discounts, 1 => Supplier discounts
|
||||
* $cannotApplyDiscount Set it to prevent form to apply discount
|
||||
* $backtopage URL to come back to from discount modification pages
|
||||
*/
|
||||
|
||||
$classname = get_class($object);
|
||||
$isInvoice = in_array($object->element, array('facture', 'invoice', 'facture_fourn', 'invoice_supplier'));
|
||||
$isNewObject = empty($object->id) && empty($object->rowid);
|
||||
|
||||
// Relative and absolute discounts
|
||||
$addrelativediscount = '<a href="' . DOL_URL_ROOT . '/comm/remise.php?id=' . $thirdparty->id . '&backtopage=' . $backtopage . '">' . $langs->trans("EditRelativeDiscount") . '</a>';
|
||||
$addabsolutediscount = '<a href="' . DOL_URL_ROOT . '/comm/remx.php?id=' . $thirdparty->id . '&backtopage=' . $backtopage . '">' . $langs->trans("EditGlobalDiscounts") . '</a>';
|
||||
$viewabsolutediscount = '<a href="' . DOL_URL_ROOT . '/comm/remx.php?id=' . $thirdparty->id . '&backtopage=' . $backtopage . '">' . $langs->trans("ViewAvailableGlobalDiscounts") . '</a>';
|
||||
|
||||
$fixedDiscount = $thirdparty->remise_percent;
|
||||
|
||||
if(! empty($discount_type)) {
|
||||
$fixedDiscount = $thirdparty->remise_supplier_percent;
|
||||
}
|
||||
|
||||
$translationKey = ! empty($discount_type) ? 'HasRelativeDiscountFromSupplier' : 'CompanyHasRelativeDiscount';
|
||||
if ($fixedDiscount > 0)
|
||||
print $langs->trans($translationKey, $fixedDiscount).'.';
|
||||
else
|
||||
print $langs->trans($translationKey).'.';
|
||||
if($isNewObject) print ' ('.$addrelativediscount.')';
|
||||
|
||||
// Is there is commercial discount or down payment available ?
|
||||
if ($absolute_discount > 0) {
|
||||
|
||||
if ($cannotApplyDiscount || ! $isInvoice || $isNewObject || $object->statut > $classname::STATUS_DRAFT || $object->type == $classname::TYPE_CREDIT_NOTE || $object->type == $classname::TYPE_DEPOSIT) {
|
||||
$translationKey = ! empty($discount_type) ? 'HasAbsoluteDiscountFromSupplier' : 'CompanyHasAbsoluteDiscount';
|
||||
$text = $langs->trans($translationKey, price($absolute_discount), $langs->transnoentities("Currency" . $conf->currency)).'.';
|
||||
|
||||
if ($isInvoice && ! $isNewObject && $object->statut > $classname::STATUS_DRAFT && $object->type != $classname::TYPE_CREDIT_NOTE && $object->type != $classname::TYPE_DEPOSIT) {
|
||||
$text = $form->textwithpicto($text, $langs->trans('AbsoluteDiscountUse'));
|
||||
}
|
||||
|
||||
if ($isNewObject) {
|
||||
$text.= ' ('.$addabsolutediscount.')';
|
||||
}
|
||||
|
||||
print '<br>'.$text;
|
||||
} else {
|
||||
// Discount available of type fixed amount (not credit note)
|
||||
$more = '(' . $addabsolutediscount . ')';
|
||||
$form->form_remise_dispo($_SERVER["PHP_SELF"] . '?facid=' . $object->id, GETPOST('discountid'), 'remise_id', $thirdparty->id, $absolute_discount, $filterabsolutediscount, $resteapayer, $more, 0, $discount_type);
|
||||
}
|
||||
}
|
||||
|
||||
// Is there credit notes availables ?
|
||||
if ($absolute_creditnote > 0) {
|
||||
|
||||
// If validated, we show link "add credit note to payment"
|
||||
if ($cannotApplyDiscount || ! $isInvoice || $isNewObject || $object->statut != $classname::STATUS_VALIDATED || $object->type == $classname::TYPE_CREDIT_NOTE) {
|
||||
$translationKey = ! empty($discount_type) ? 'HasCreditNoteFromSupplier' : 'CompanyHasCreditNote';
|
||||
$text = $langs->trans($translationKey, price($absolute_creditnote), $langs->transnoentities("Currency" . $conf->currency)) . '.';
|
||||
|
||||
if ($isInvoice && ! $isNewObject && $object->statut == $classname::STATUS_DRAFT && $object->type != $classname::TYPE_DEPOSIT) {
|
||||
$text = $form->textwithpicto($text, $langs->trans('CreditNoteDepositUse'));
|
||||
}
|
||||
|
||||
if ($absolute_discount <= 0 || $isNewObject) {
|
||||
$text.= '('.$addabsolutediscount.')';
|
||||
}
|
||||
|
||||
print '<br>'.$text;
|
||||
} else { // We can add a credit note on a down payment or standard invoice or situation invoice
|
||||
// There is credit notes discounts available
|
||||
$more = $isInvoice && ! $isNewObject ? ' (' . $viewabsolutediscount . ')' : '';
|
||||
$form->form_remise_dispo($_SERVER["PHP_SELF"] . '?facid=' . $object->id, 0, 'remise_id_for_payment', $thirdparty->id, $absolute_creditnote, $filtercreditnote, 0, $more, 0, $discount_type); // We allow credit note even if amount is higher
|
||||
}
|
||||
}
|
||||
|
||||
if($absolute_discount <= 0 && $absolute_creditnote <= 0) {
|
||||
$translationKey = ! empty($discount_type) ? 'HasNoAbsoluteDiscountFromSupplier' : 'CompanyHasNoAbsoluteDiscount';
|
||||
print '<br>'.$langs->trans($translationKey).'.';
|
||||
|
||||
if ($isInvoice && $object->statut == $classname::STATUS_DRAFT && $object->type != $classname::TYPE_CREDIT_NOTE && $object->type != $classname::TYPE_DEPOSIT) {
|
||||
print ' (' . $addabsolutediscount . ')';
|
||||
}
|
||||
}
|
||||
|
||||
@ -322,8 +322,12 @@ else {
|
||||
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;
|
||||
}
|
||||
?>
|
||||
<td class="nobottom nowrap linecoldiscount" align="right"><input type="text" size="1" name="remise_percent" id="remise_percent" class="flat right" value="<?php echo (isset($_POST["remise_percent"])?GETPOST("remise_percent",'alpha',2):$buyer->remise_percent); ?>"><span class="hideonsmartphone">%</span></td>
|
||||
<td class="nobottom nowrap linecoldiscount" align="right"><input type="text" size="1" name="remise_percent" id="remise_percent" class="flat right" value="<?php echo (isset($_POST["remise_percent"])?GETPOST("remise_percent",'alpha',2):$remise_percent); ?>"><span class="hideonsmartphone">%</span></td>
|
||||
<?php
|
||||
if ($this->situation_cycle_ref) {
|
||||
$coldisplay++;
|
||||
@ -725,10 +729,11 @@ jQuery(document).ready(function() {
|
||||
?>
|
||||
|
||||
/* To process customer price per quantity */
|
||||
var pbq = $('option:selected', this).attr('data-pbq');
|
||||
var pbqqty = $('option:selected', this).attr('data-pbqqty');
|
||||
var pbqpercent = $('option:selected', this).attr('data-pbqpercent');
|
||||
if (jQuery('#idprod').val() > 0 && typeof pbq !== "undefined")
|
||||
var pbq = parseInt($('option:selected', this).attr('data-pbq'));
|
||||
var pbqqty = parseFloat($('option:selected', this).attr('data-pbqqty'));
|
||||
var pbqpercent = parseFloat($('option:selected', this).attr('data-pbqpercent'));
|
||||
|
||||
if ((jQuery('#idprod').val() > 0 || jQuery('#idprodfournprice').val()) && typeof pbq !== "undefined")
|
||||
{
|
||||
console.log("We choose a price by quanty price_by_qty id = "+pbq+" price_by_qty qty = "+pbqqty+" price_by_qty percent = "+pbqpercent);
|
||||
jQuery("#pbq").val(pbq);
|
||||
@ -782,7 +787,6 @@ function setforfree() {
|
||||
jQuery("#tva_tx").show();
|
||||
jQuery("#buying_price").val('').show();
|
||||
jQuery("#fournprice_predef").hide();
|
||||
jQuery("#title_fourn_ref").show();
|
||||
jQuery("#title_vat").show();
|
||||
jQuery("#title_up_ht").show();
|
||||
jQuery("#title_up_ht_currency").show();
|
||||
@ -806,7 +810,6 @@ function setforpredef() {
|
||||
jQuery("#fourn_ref").hide();
|
||||
jQuery("#tva_tx").hide();
|
||||
jQuery("#buying_price").show();
|
||||
jQuery("#title_fourn_ref").hide();
|
||||
jQuery("#title_vat").hide();
|
||||
jQuery("#title_up_ht").hide();
|
||||
jQuery("#title_up_ht_currency").hide();
|
||||
|
||||
@ -73,6 +73,7 @@ if (empty($outputalsopricetotalwithtax)) $outputalsopricetotalwithtax=0;
|
||||
print img_object($langs->trans("ShowReduc"),'reduc').' ';
|
||||
if ($line->description == '(DEPOSIT)') $txt=$langs->trans("Deposit");
|
||||
elseif ($line->description == '(EXCESS RECEIVED)') $txt=$langs->trans("ExcessReceived");
|
||||
elseif ($line->description == '(EXCESS PAID)') $txt=$langs->trans("ExcessPaid");
|
||||
//else $txt=$langs->trans("Discount");
|
||||
print $txt;
|
||||
?>
|
||||
@ -101,6 +102,12 @@ if (empty($outputalsopricetotalwithtax)) $outputalsopricetotalwithtax=0;
|
||||
$discount->fetch($line->fk_remise_except);
|
||||
echo ($txt?' - ':'').$langs->transnoentities("DiscountFromExcessReceived",$discount->getNomUrl(0));
|
||||
}
|
||||
elseif ($line->description == '(EXCESS PAID)' && $objp->fk_remise_except > 0)
|
||||
{
|
||||
$discount=new DiscountAbsolute($this->db);
|
||||
$discount->fetch($line->fk_remise_except);
|
||||
echo ($txt?' - ':'').$langs->transnoentities("DiscountFromExcessPaid",$discount->getNomUrl(0));
|
||||
}
|
||||
else
|
||||
{
|
||||
echo ($txt?' - ':'').dol_htmlentitiesbr($line->description);
|
||||
|
||||
@ -331,33 +331,26 @@ if ($id > 0 || ! empty($ref))
|
||||
print '<table class="border" width="100%">';
|
||||
|
||||
// Discounts for third party
|
||||
if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
|
||||
$filterabsolutediscount = "fk_facture_source IS NULL"; // If we want deposit to be substracted to payments only and not to total of final invoice
|
||||
$filtercreditnote = "fk_facture_source IS NOT NULL"; // If we want deposit to be substracted to payments only and not to total of final invoice
|
||||
} else {
|
||||
$filterabsolutediscount = "fk_facture_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS RECEIVED)%')";
|
||||
$filtercreditnote = "fk_facture_source IS NOT NULL AND (description NOT LIKE '(DEPOSIT)%' OR description LIKE '(EXCESS RECEIVED)%')";
|
||||
}
|
||||
|
||||
print '<tr><td class="titlefield">'.$langs->trans('Discounts').'</td><td colspan="3">';
|
||||
if ($soc->remise_percent) print $langs->trans("CompanyHasRelativeDiscount",$soc->remise_percent);
|
||||
else print $langs->trans("CompanyHasNoRelativeDiscount");
|
||||
print '. ';
|
||||
$absolute_discount=$soc->getAvailableDiscounts('','fk_facture_source IS NULL');
|
||||
$absolute_creditnote=$soc->getAvailableDiscounts('','fk_facture_source IS NOT NULL');
|
||||
|
||||
$absolute_discount=$soc->getAvailableDiscounts('',$filterabsolutediscount);
|
||||
$absolute_creditnote=$soc->getAvailableDiscounts('',$filtercreditnote);
|
||||
$absolute_discount=price2num($absolute_discount,'MT');
|
||||
$absolute_creditnote=price2num($absolute_creditnote,'MT');
|
||||
if ($absolute_discount)
|
||||
{
|
||||
if ($object->statut > Commande::STATUS_DRAFT)
|
||||
{
|
||||
print $langs->trans("CompanyHasAbsoluteDiscount",price($absolute_discount),$langs->transnoentities("Currency".$conf->currency));
|
||||
}
|
||||
else
|
||||
{
|
||||
// Remise dispo de type non avoir
|
||||
$filter='fk_facture_source IS NULL';
|
||||
print '<br>';
|
||||
$form->form_remise_dispo($_SERVER["PHP_SELF"].'?id='.$object->id,0,'remise_id',$soc->id,$absolute_discount,$filter, 0, '', 1);
|
||||
}
|
||||
}
|
||||
if ($absolute_creditnote)
|
||||
{
|
||||
print $langs->trans("CompanyHasCreditNote",price($absolute_creditnote),$langs->transnoentities("Currency".$conf->currency)).'. ';
|
||||
}
|
||||
if (! $absolute_discount && ! $absolute_creditnote) print $langs->trans("CompanyHasNoAbsoluteDiscount").'.';
|
||||
|
||||
$thirdparty = $soc;
|
||||
$discount_type = 0;
|
||||
$backtopage = urlencode($_SERVER["PHP_SELF"] . '?id=' . $object->id);
|
||||
$cannotApplyDiscount = 1;
|
||||
include DOL_DOCUMENT_ROOT.'/core/tpl/object_discounts.tpl.php';
|
||||
print '</td></tr>';
|
||||
|
||||
// Date
|
||||
|
||||
@ -258,6 +258,39 @@ if ($object->id > 0)
|
||||
print "</td>";
|
||||
print '</tr>';
|
||||
|
||||
// Relative discounts (Discounts-Drawbacks-Rebates)
|
||||
print '<tr><td class="nowrap">';
|
||||
print '<table width="100%" class="nobordernopadding"><tr><td class="nowrap">';
|
||||
print $langs->trans("CustomerRelativeDiscountShort");
|
||||
print '<td><td align="right">';
|
||||
if ($user->rights->societe->creer && !$user->societe_id > 0)
|
||||
{
|
||||
print '<a href="'.DOL_URL_ROOT.'/comm/remise.php?id='.$object->id.'">'.img_edit($langs->trans("Modify")).'</a>';
|
||||
}
|
||||
print '</td></tr></table>';
|
||||
print '</td><td>'.($object->remise_supplier_percent?'<a href="'.DOL_URL_ROOT.'/comm/remise.php?id='.$object->id.'">'.$object->remise_supplier_percent.'%</a>':'').'</td>';
|
||||
print '</tr>';
|
||||
|
||||
// Absolute discounts (Discounts-Drawbacks-Rebates)
|
||||
print '<tr><td class="nowrap">';
|
||||
print '<table width="100%" class="nobordernopadding">';
|
||||
print '<tr><td class="nowrap">';
|
||||
print $langs->trans("CustomerAbsoluteDiscountShort");
|
||||
print '<td><td align="right">';
|
||||
if ($user->rights->societe->creer && !$user->societe_id > 0)
|
||||
{
|
||||
print '<a href="'.DOL_URL_ROOT.'/comm/remx.php?id='.$object->id.'&backtopage='.urlencode($_SERVER["PHP_SELF"].'?socid='.$object->id).'">'.img_edit($langs->trans("Modify")).'</a>';
|
||||
}
|
||||
print '</td></tr></table>';
|
||||
print '</td>';
|
||||
print '<td>';
|
||||
$amount_discount=$object->getAvailableDiscounts('', '', 0, 1);
|
||||
if ($amount_discount < 0) dol_print_error($db,$object->error);
|
||||
if ($amount_discount > 0) print '<a href="'.DOL_URL_ROOT.'/comm/remx.php?id='.$object->id.'&backtopage='.urlencode($_SERVER["PHP_SELF"].'?socid='.$object->id).'">'.price($amount_discount,1,$langs,1,-1,-1,$conf->currency).'</a>';
|
||||
//else print $langs->trans("DiscountNone");
|
||||
print '</td>';
|
||||
print '</tr>';
|
||||
|
||||
print '<tr class="nowrap">';
|
||||
print '<td>';
|
||||
print $form->editfieldkey("OrderMinAmount",'supplier_order_min_amount',$object->supplier_order_min_amount,$object,$user->rights->societe->creer);
|
||||
@ -611,7 +644,7 @@ if ($object->id > 0)
|
||||
print '<tr class="liste_titre">';
|
||||
print '<td colspan="3">';
|
||||
print '<table class="nobordernopadding" width="100%"><tr><td>'.$langs->trans("LastSupplierOrders",($num<$MAXLIST?"":$MAXLIST)).'</td>';
|
||||
print '<td align="right"><a class="notasortlink" href="'.DOL_URL_ROOT.'/commande/list.php?socid='.$object->id.'">'.$langs->trans("AllOrders").' <span class="badge">'.$num.'</span></td>';
|
||||
print '<td align="right"><a class="notasortlink" href="'.DOL_URL_ROOT.'/fourn/commande/list.php?socid='.$object->id.'">'.$langs->trans("AllOrders").' <span class="badge">'.$num.'</span></td>';
|
||||
print '<td width="20px" align="right"><a href="'.DOL_URL_ROOT.'/commande/stats/index.php?mode=supplier&socid='.$object->id.'">'.img_picto($langs->trans("Statistics"),'stats').'</a></td>';
|
||||
print '</tr></table>';
|
||||
print '</td></tr>';
|
||||
|
||||
@ -894,6 +894,107 @@ class FactureFournisseur extends CommonInvoice
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a discount line into an invoice (as an invoice line) using an existing absolute discount (Consume the discount)
|
||||
*
|
||||
* @param int $idremise Id of absolute discount
|
||||
* @return int >0 if OK, <0 if KO
|
||||
*/
|
||||
function insert_discount($idremise)
|
||||
{
|
||||
global $langs;
|
||||
|
||||
include_once DOL_DOCUMENT_ROOT.'/core/lib/price.lib.php';
|
||||
include_once DOL_DOCUMENT_ROOT.'/core/class/discount.class.php';
|
||||
|
||||
$this->db->begin();
|
||||
|
||||
$remise=new DiscountAbsolute($this->db);
|
||||
$result=$remise->fetch($idremise);
|
||||
|
||||
if ($result > 0)
|
||||
{
|
||||
if ($remise->fk_invoice_supplier) // Protection against multiple submission
|
||||
{
|
||||
$this->error=$langs->trans("ErrorDiscountAlreadyUsed");
|
||||
$this->db->rollback();
|
||||
return -5;
|
||||
}
|
||||
|
||||
$facligne=new SupplierInvoiceLine($this->db);
|
||||
$facligne->fk_facture_fourn=$this->id;
|
||||
$facligne->fk_remise_except=$remise->id;
|
||||
$facligne->desc=$remise->description; // Description ligne
|
||||
$facligne->vat_src_code=$remise->vat_src_code;
|
||||
$facligne->tva_tx=$remise->tva_tx;
|
||||
$facligne->subprice = -$remise->amount_ht;
|
||||
$facligne->fk_product=0; // Id produit predefini
|
||||
$facligne->product_type=0;
|
||||
$facligne->qty=1;
|
||||
$facligne->remise_percent=0;
|
||||
$facligne->rang=-1;
|
||||
$facligne->info_bits=2;
|
||||
|
||||
// Get buy/cost price of invoice that is source of discount
|
||||
if ($remise->fk_invoice_supplier_source > 0)
|
||||
{
|
||||
$srcinvoice=new FactureFournisseur($this->db);
|
||||
$srcinvoice->fetch($remise->fk_invoice_supplier_source);
|
||||
$totalcostpriceofinvoice=0;
|
||||
include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmargin.class.php'; // TODO Move this into commonobject
|
||||
$formmargin=new FormMargin($this->db);
|
||||
$arraytmp=$formmargin->getMarginInfosArray($srcinvoice, false);
|
||||
$facligne->pa_ht = $arraytmp['pa_total'];
|
||||
}
|
||||
|
||||
$facligne->total_ht = -$remise->amount_ht;
|
||||
$facligne->total_tva = -$remise->amount_tva;
|
||||
$facligne->total_ttc = -$remise->amount_ttc;
|
||||
|
||||
$facligne->multicurrency_subprice = -$remise->multicurrency_subprice;
|
||||
$facligne->multicurrency_total_ht = -$remise->multicurrency_total_ht;
|
||||
$facligne->multicurrency_total_tva = -$remise->multicurrency_total_tva;
|
||||
$facligne->multicurrency_total_ttc = -$remise->multicurrency_total_ttc;
|
||||
|
||||
$lineid=$facligne->insert();
|
||||
if ($lineid > 0)
|
||||
{
|
||||
$result=$this->update_price(1);
|
||||
if ($result > 0)
|
||||
{
|
||||
// Create link between discount and invoice line
|
||||
$result=$remise->link_to_invoice($lineid,0,'supplier');
|
||||
if ($result < 0)
|
||||
{
|
||||
$this->error=$remise->error;
|
||||
$this->db->rollback();
|
||||
return -4;
|
||||
}
|
||||
|
||||
$this->db->commit();
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->error=$facligne->error;
|
||||
$this->db->rollback();
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->error=$facligne->error;
|
||||
$this->db->rollback();
|
||||
return -2;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->db->rollback();
|
||||
return -3;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Delete invoice from database
|
||||
@ -927,6 +1028,33 @@ class FactureFournisseur extends CommonInvoice
|
||||
// Fin appel triggers
|
||||
}
|
||||
|
||||
if (! $error) {
|
||||
// If invoice was converted into a discount not yet consumed, we remove discount
|
||||
$sql = 'DELETE FROM ' . MAIN_DB_PREFIX . 'societe_remise_except';
|
||||
$sql .= ' WHERE fk_invoice_supplier_source = ' . $rowid;
|
||||
$sql .= ' AND fk_invoice_supplier_line IS NULL';
|
||||
$resql = $this->db->query($sql);
|
||||
|
||||
// If invoice has consumned discounts
|
||||
$this->fetch_lines();
|
||||
$list_rowid_det = array ();
|
||||
foreach ($this->lines as $key => $invoiceline) {
|
||||
$list_rowid_det[] = $invoiceline->rowid;
|
||||
}
|
||||
|
||||
// Consumned discounts are freed
|
||||
if (count($list_rowid_det)) {
|
||||
$sql = 'UPDATE ' . MAIN_DB_PREFIX . 'societe_remise_except';
|
||||
$sql .= ' SET fk_invoice_supplier = NULL, fk_invoice_supplier_line = NULL';
|
||||
$sql .= ' WHERE fk_invoice_supplier_line IN (' . join(',', $list_rowid_det) . ')';
|
||||
|
||||
dol_syslog(get_class($this) . "::delete", LOG_DEBUG);
|
||||
if (! $this->db->query($sql)) {
|
||||
$error ++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (! $error)
|
||||
{
|
||||
$sql = 'DELETE FROM '.MAIN_DB_PREFIX.'facture_fourn_det WHERE fk_facture_fourn = '.$rowid.';';
|
||||
@ -1668,6 +1796,22 @@ class FactureFournisseur extends CommonInvoice
|
||||
$rowid = $this->id;
|
||||
}
|
||||
|
||||
$this->db->begin();
|
||||
|
||||
// Libere remise liee a ligne de facture
|
||||
$sql = 'UPDATE ' . MAIN_DB_PREFIX . 'societe_remise_except';
|
||||
$sql .= ' SET fk_invoice_supplier_line = NULL';
|
||||
$sql .= ' WHERE fk_invoice_supplier_line = ' . $rowid;
|
||||
|
||||
dol_syslog(get_class($this) . "::deleteline", LOG_DEBUG);
|
||||
$result = $this->db->query($sql);
|
||||
if (! $result)
|
||||
{
|
||||
$this->error = $this->db->error();
|
||||
$this->db->rollback();
|
||||
return - 2;
|
||||
}
|
||||
|
||||
$line = new SupplierInvoiceLine($this->db);
|
||||
|
||||
if ($line->fetch($rowid) < 1) {
|
||||
@ -1677,12 +1821,24 @@ class FactureFournisseur extends CommonInvoice
|
||||
$res = $line->delete($notrigger);
|
||||
|
||||
if ($res < 1) {
|
||||
$this->errors[] = $line->error;
|
||||
$this->errors[] = $line->error;
|
||||
$this->db->rollback();
|
||||
return - 3;
|
||||
} else {
|
||||
$res = $this->update_price();
|
||||
}
|
||||
$res = $this->update_price();
|
||||
|
||||
return $res;
|
||||
if ($res > 0)
|
||||
{
|
||||
$this->db->commit();
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->db->rollback();
|
||||
$this->error = $this->db->lasterror();
|
||||
return - 4;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -1401,7 +1401,7 @@ if ($action=='create')
|
||||
$availability_id = (!empty($objectsrc->availability_id)?$objectsrc->availability_id:(!empty($soc->availability_id)?$soc->availability_id:0));
|
||||
$shipping_method_id = (! empty($objectsrc->shipping_method_id)?$objectsrc->shipping_method_id:(! empty($soc->shipping_method_id)?$soc->shipping_method_id:0));
|
||||
$demand_reason_id = (!empty($objectsrc->demand_reason_id)?$objectsrc->demand_reason_id:(!empty($soc->demand_reason_id)?$soc->demand_reason_id:0));
|
||||
$remise_percent = (!empty($objectsrc->remise_percent)?$objectsrc->remise_percent:(!empty($soc->remise_percent)?$soc->remise_percent:0));
|
||||
$remise_percent = (!empty($objectsrc->remise_percent)?$objectsrc->remise_percent:(!empty($soc->remise_supplier_percent)?$soc->remise_supplier_percent:0));
|
||||
$remise_absolue = (!empty($objectsrc->remise_absolue)?$objectsrc->remise_absolue:(!empty($soc->remise_absolue)?$soc->remise_absolue:0));
|
||||
$dateinvoice = empty($conf->global->MAIN_AUTOFILL_DATE)?-1:'';
|
||||
|
||||
@ -1439,7 +1439,7 @@ if ($action=='create')
|
||||
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
|
||||
print '<input type="hidden" name="action" value="add">';
|
||||
print '<input type="hidden" name="socid" value="' . $soc->id . '">' . "\n";
|
||||
print '<input type="hidden" name="remise_percent" value="' . $soc->remise_percent . '">';
|
||||
print '<input type="hidden" name="remise_percent" value="' . $soc->remise_supplier_percent . '">';
|
||||
print '<input type="hidden" name="origin" value="' . $origin . '">';
|
||||
print '<input type="hidden" name="originid" value="' . $originid . '">';
|
||||
if (!empty($currency_tx)) print '<input type="hidden" name="originmulticurrency_tx" value="' . $currency_tx . '">';
|
||||
@ -1480,6 +1480,21 @@ if ($action=='create')
|
||||
}
|
||||
print '</td>';
|
||||
|
||||
if ($societe->id > 0)
|
||||
{
|
||||
// Discounts for third party
|
||||
print '<tr><td>' . $langs->trans('Discounts') . '</td><td>';
|
||||
|
||||
$absolute_discount = $societe->getAvailableDiscounts('', '', 0, 1);
|
||||
|
||||
$thirdparty = $societe;
|
||||
$discount_type = 1;
|
||||
$backtopage = urlencode($_SERVER["PHP_SELF"] . '?socid=' . $thirdparty->id . '&action=' . $action . '&origin=' . GETPOST('origin') . '&originid=' . GETPOST('originid'));
|
||||
include DOL_DOCUMENT_ROOT.'/core/tpl/object_discounts.tpl.php';
|
||||
|
||||
print '</td></tr>';
|
||||
}
|
||||
|
||||
// Ref supplier
|
||||
print '<tr><td>'.$langs->trans('RefSupplier').'</td><td><input name="refsupplier" type="text"></td>';
|
||||
print '</tr>';
|
||||
@ -1860,6 +1875,29 @@ elseif (! empty($object->id))
|
||||
print '<td>'.$author->getNomUrl(1, '', 0, 0, 0).'</td>';
|
||||
print '</tr>';
|
||||
|
||||
// Relative and absolute discounts
|
||||
if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
|
||||
$filterabsolutediscount = "fk_invoice_supplier_source IS NULL"; // If we want deposit to be substracted to payments only and not to total of final invoice
|
||||
$filtercreditnote = "fk_invoice_supplier_source IS NOT NULL"; // If we want deposit to be substracted to payments only and not to total of final invoice
|
||||
} else {
|
||||
$filterabsolutediscount = "fk_invoice_supplier_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS PAID)%')";
|
||||
$filtercreditnote = "fk_invoice_supplier_source IS NOT NULL AND (description NOT LIKE '(DEPOSIT)%' OR description LIKE '(EXCESS PAID)%')";
|
||||
}
|
||||
|
||||
$absolute_discount = $societe->getAvailableDiscounts('', $filterabsolutediscount, 0, 1);
|
||||
$absolute_creditnote = $societe->getAvailableDiscounts('', $filtercreditnote, 0, 1);
|
||||
$absolute_discount = price2num($absolute_discount, 'MT');
|
||||
$absolute_creditnote = price2num($absolute_creditnote, 'MT');
|
||||
|
||||
print '<tr><td class="titlefield">' . $langs->trans('Discounts') . '</td><td>';
|
||||
|
||||
$thirdparty = $societe;
|
||||
$discount_type = 1;
|
||||
$backtopage = urlencode($_SERVER["PHP_SELF"] . '?id=' . $object->id);
|
||||
include DOL_DOCUMENT_ROOT.'/core/tpl/object_discounts.tpl.php';
|
||||
|
||||
print '</td></tr>';
|
||||
|
||||
// Conditions de reglement par defaut
|
||||
$langs->load('bills');
|
||||
print '<tr><td class="nowrap">';
|
||||
@ -2702,7 +2740,7 @@ elseif (! empty($object->id))
|
||||
}
|
||||
|
||||
// Presend form
|
||||
$modelmail='supplier_order_send';
|
||||
$modelmail='order_supplier_send';
|
||||
$defaulttopic='SendOrderRef';
|
||||
$diroutput = $conf->fournisseur->commande->dir_output;
|
||||
$trackid = 'sor'.$object->id;
|
||||
|
||||
@ -36,6 +36,7 @@ require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.class.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/modules/supplier_invoice/modules_facturefournisseur.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/fourn/class/paiementfourn.class.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/class/discount.class.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/lib/fourn.lib.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
|
||||
@ -266,6 +267,14 @@ if (empty($reshook))
|
||||
}
|
||||
}
|
||||
|
||||
// Delete link of credit note to invoice
|
||||
else if ($action == 'unlinkdiscount' && $user->rights->fournisseur->facture->creer)
|
||||
{
|
||||
$discount = new DiscountAbsolute($db);
|
||||
$result = $discount->fetch(GETPOST("discountid"));
|
||||
$discount->unlink_invoice();
|
||||
}
|
||||
|
||||
elseif ($action == 'confirm_paid' && $confirm == 'yes' && $user->rights->fournisseur->facture->creer)
|
||||
{
|
||||
$object->fetch($id);
|
||||
@ -317,12 +326,12 @@ if (empty($reshook))
|
||||
}
|
||||
|
||||
// Multicurrency Code
|
||||
else if ($action == 'setmulticurrencycode' && $user->rights->facture->creer) {
|
||||
else if ($action == 'setmulticurrencycode' && $user->rights->fournisseur->facture->creer) {
|
||||
$result = $object->setMulticurrencyCode(GETPOST('multicurrency_code', 'alpha'));
|
||||
}
|
||||
|
||||
// Multicurrency rate
|
||||
else if ($action == 'setmulticurrencyrate' && $user->rights->facture->creer) {
|
||||
else if ($action == 'setmulticurrencyrate' && $user->rights->fournisseur->facture->creer) {
|
||||
$result = $object->setMulticurrencyRate(price2num(GETPOST('multicurrency_tx', 'alpha')));
|
||||
}
|
||||
|
||||
@ -376,6 +385,187 @@ if (empty($reshook))
|
||||
$result=$object->update($user);
|
||||
if ($result < 0) dol_print_error($db,$object->error);
|
||||
}
|
||||
elseif ($action == "setabsolutediscount" && $user->rights->fournisseur->facture->creer)
|
||||
{
|
||||
// POST[remise_id] or POST[remise_id_for_payment]
|
||||
|
||||
// We use the credit to reduce amount of invoice
|
||||
if (! empty($_POST["remise_id"])) {
|
||||
$ret = $object->fetch($id);
|
||||
if ($ret > 0) {
|
||||
$result = $object->insert_discount($_POST["remise_id"]);
|
||||
if ($result < 0) {
|
||||
setEventMessages($object->error, $object->errors, 'errors');
|
||||
}
|
||||
} else {
|
||||
dol_print_error($db, $object->error);
|
||||
}
|
||||
}
|
||||
// We use the credit to reduce remain to pay
|
||||
if (! empty($_POST["remise_id_for_payment"]))
|
||||
{
|
||||
require_once DOL_DOCUMENT_ROOT . '/core/class/discount.class.php';
|
||||
$discount = new DiscountAbsolute($db);
|
||||
$discount->fetch($_POST["remise_id_for_payment"]);
|
||||
|
||||
//var_dump($object->getRemainToPay(0));
|
||||
//var_dump($discount->amount_ttc);exit;
|
||||
if ($discount->amount_ttc > $object->getRemainToPay(0))
|
||||
{
|
||||
// TODO Split the discount in 2 automatically
|
||||
$error++;
|
||||
setEventMessages($langs->trans("ErrorDiscountLargerThanRemainToPaySplitItBefore"), null, 'errors');
|
||||
}
|
||||
|
||||
if (! $error)
|
||||
{
|
||||
$result = $discount->link_to_invoice(0, $id);
|
||||
if ($result < 0) {
|
||||
setEventMessages($discount->error, $discount->errors, 'errors');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE))
|
||||
{
|
||||
$outputlangs = $langs;
|
||||
$newlang = '';
|
||||
if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id','aZ09')) $newlang = GETPOST('lang_id','aZ09');
|
||||
if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $object->thirdparty->default_lang;
|
||||
if (! empty($newlang)) {
|
||||
$outputlangs = new Translate("", $conf);
|
||||
$outputlangs->setDefaultLang($newlang);
|
||||
}
|
||||
$ret = $object->fetch($id); // Reload to get new records
|
||||
|
||||
$result = $object->generateDocument($object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
|
||||
if ($result < 0) setEventMessages($object->error, $object->errors, 'errors');
|
||||
}
|
||||
}
|
||||
// Convertir en reduc
|
||||
else if ($action == 'confirm_converttoreduc' && $confirm == 'yes' && $user->rights->fournisseur->facture->creer)
|
||||
{
|
||||
$object->fetch($id);
|
||||
$object->fetch_thirdparty();
|
||||
//$object->fetch_lines(); // Already done into fetch
|
||||
|
||||
// Check if there is already a discount (protection to avoid duplicate creation when resubmit post)
|
||||
$discountcheck=new DiscountAbsolute($db);
|
||||
$result=$discountcheck->fetch(0,0,$object->id);
|
||||
|
||||
$canconvert=0;
|
||||
if ($object->type == FactureFournisseur::TYPE_DEPOSIT && empty($discountcheck->id)) $canconvert=1; // we can convert deposit into discount if deposit is payed (completely, partially or not at all) and not already converted (see real condition into condition used to show button converttoreduc)
|
||||
if (($object->type == FactureFournisseur::TYPE_CREDIT_NOTE || $object->type == FactureFournisseur::TYPE_STANDARD) && $object->paye == 0 && empty($discountcheck->id)) $canconvert=1; // we can convert credit note into discount if credit note is not payed back and not already converted and amount of payment is 0 (see real condition into condition used to show button converttoreduc)
|
||||
if ($canconvert)
|
||||
{
|
||||
$db->begin();
|
||||
|
||||
$amount_ht = $amount_tva = $amount_ttc = array();
|
||||
|
||||
// Loop on each vat rate
|
||||
$i = 0;
|
||||
foreach ($object->lines as $line)
|
||||
{
|
||||
if ($line->product_type < 9 && $line->total_ht != 0) // Remove lines with product_type greater than or equal to 9
|
||||
{ // no need to create discount if amount is null
|
||||
$amount_ht[$line->tva_tx] += $line->total_ht;
|
||||
$amount_tva[$line->tva_tx] += $line->total_tva;
|
||||
$amount_ttc[$line->tva_tx] += $line->total_ttc;
|
||||
$i ++;
|
||||
}
|
||||
}
|
||||
|
||||
// Insert one discount by VAT rate category
|
||||
$discount = new DiscountAbsolute($db);
|
||||
if ($object->type == FactureFournisseur::TYPE_CREDIT_NOTE)
|
||||
$discount->description = '(CREDIT_NOTE)';
|
||||
elseif ($object->type == FactureFournisseur::TYPE_DEPOSIT)
|
||||
$discount->description = '(DEPOSIT)';
|
||||
elseif ($object->type == FactureFournisseur::TYPE_STANDARD || $object->type == FactureFournisseur::TYPE_REPLACEMENT || $object->type == FactureFournisseur::TYPE_SITUATION)
|
||||
$discount->description = '(EXCESS PAID)';
|
||||
else {
|
||||
setEventMessages($langs->trans('CantConvertToReducAnInvoiceOfThisType'), null, 'errors');
|
||||
}
|
||||
$discount->discount_type = 1; // Supplier discount
|
||||
$discount->fk_soc = $object->socid;
|
||||
$discount->fk_invoice_supplier_source = $object->id;
|
||||
|
||||
$error = 0;
|
||||
|
||||
if ($object->type == FactureFournisseur::TYPE_STANDARD || $object->type == FactureFournisseur::TYPE_REPLACEMENT || $object->type == FactureFournisseur::TYPE_SITUATION)
|
||||
{
|
||||
// If we're on a standard invoice, we have to get excess paid to create a discount in TTC without VAT
|
||||
|
||||
$sql = 'SELECT SUM(pf.amount) as total_paiements';
|
||||
$sql.= ' FROM '.MAIN_DB_PREFIX.'paiementfourn_facturefourn as pf, '.MAIN_DB_PREFIX.'paiementfourn as p';
|
||||
$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_paiement as c ON p.fk_paiement = c.id AND c.entity IN (' . getEntity('c_paiement') . ')';
|
||||
$sql.= ' WHERE pf.fk_facturefourn = '.$object->id;
|
||||
$sql.= ' AND pf.fk_paiementfourn = p.rowid';
|
||||
$sql.= ' AND p.entity IN (' . getEntity('facture').')';
|
||||
$sql.= ' ORDER BY p.datep, p.tms';
|
||||
|
||||
$resql = $db->query($sql);
|
||||
if (! $resql) dol_print_error($db);
|
||||
|
||||
$res = $db->fetch_object($resql);
|
||||
$total_paiements = $res->total_paiements;
|
||||
|
||||
$discount->amount_ht = $discount->amount_ttc = $total_paiements - $object->total_ttc;
|
||||
$discount->amount_tva = 0;
|
||||
$discount->tva_tx = 0;
|
||||
|
||||
$result = $discount->create($user);
|
||||
if ($result < 0)
|
||||
{
|
||||
$error++;
|
||||
}
|
||||
|
||||
}
|
||||
if ($object->type == FactureFournisseur::TYPE_CREDIT_NOTE || $object->type == FactureFournisseur::TYPE_DEPOSIT)
|
||||
{
|
||||
foreach ($amount_ht as $tva_tx => $xxx)
|
||||
{
|
||||
$discount->amount_ht = abs($amount_ht[$tva_tx]);
|
||||
$discount->amount_tva = abs($amount_tva[$tva_tx]);
|
||||
$discount->amount_ttc = abs($amount_ttc[$tva_tx]);
|
||||
$discount->tva_tx = abs($tva_tx);
|
||||
|
||||
$result = $discount->create($user);
|
||||
if ($result < 0)
|
||||
{
|
||||
$error++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (empty($error))
|
||||
{
|
||||
if($object->type != FactureFournisseur::TYPE_DEPOSIT) {
|
||||
// Classe facture
|
||||
$result = $object->set_paid($user);
|
||||
if ($result >= 0)
|
||||
{
|
||||
$db->commit();
|
||||
}
|
||||
else
|
||||
{
|
||||
setEventMessages($object->error, $object->errors, 'errors');
|
||||
$db->rollback();
|
||||
}
|
||||
} else {
|
||||
$db->commit();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
setEventMessages($discount->error, $discount->errors, 'errors');
|
||||
$db->rollback();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Delete payment
|
||||
elseif ($action == 'confirm_delete_paiement' && $confirm == 'yes' && $user->rights->fournisseur->facture->creer)
|
||||
@ -464,6 +654,7 @@ if (empty($reshook))
|
||||
// Credit note invoice
|
||||
if ($_POST['type'] == FactureFournisseur::TYPE_CREDIT_NOTE)
|
||||
{
|
||||
|
||||
$sourceinvoice = GETPOST('fac_avoir','int');
|
||||
if (! ($sourceinvoice > 0) && empty($conf->global->INVOICE_CREDIT_NOTE_STANDALONE))
|
||||
{
|
||||
@ -519,6 +710,10 @@ if (empty($reshook))
|
||||
|
||||
$id = $object->create($user);
|
||||
|
||||
if($id <= 0) {
|
||||
$error++;
|
||||
}
|
||||
|
||||
if (GETPOST('invoiceAvoirWithLines', 'int')==1 && $id>0)
|
||||
{
|
||||
$facture_source = new FactureFournisseur($db); // fetch origin object
|
||||
@ -677,7 +872,7 @@ if (empty($reshook))
|
||||
}
|
||||
|
||||
$num=count($lines);
|
||||
for ($i = 0; $i < $num; $i++)
|
||||
for ($i = 0; $i < $num; $i++) // TODO handle subprice < 0
|
||||
{
|
||||
$desc=($lines[$i]->desc?$lines[$i]->desc:$lines[$i]->libelle);
|
||||
$product_type=($lines[$i]->product_type?$lines[$i]->product_type:0);
|
||||
@ -1431,10 +1626,10 @@ if ($action == 'create')
|
||||
//$ref_client = (!empty($objectsrc->ref_client)?$object->ref_client:'');
|
||||
|
||||
$soc = $objectsrc->thirdparty;
|
||||
$cond_reglement_id = (!empty($objectsrc->cond_reglement_id)?$objectsrc->cond_reglement_id:(!empty($soc->cond_reglement_supplier_id)?$soc->cond_reglement_supplier_id:1));
|
||||
$cond_reglement_id = (!empty($objectsrc->cond_reglement_id)?$objectsrc->cond_reglement_id:(!empty($soc->cond_reglement_supplier_id)?$soc->cond_reglement_supplier_id:0)); // TODO maybe add default value option
|
||||
$mode_reglement_id = (!empty($objectsrc->mode_reglement_id)?$objectsrc->mode_reglement_id:(!empty($soc->mode_reglement_supplier_id)?$soc->mode_reglement_supplier_id:0));
|
||||
$fk_account = (! empty($objectsrc->fk_account)?$objectsrc->fk_account:(! empty($soc->fk_account)?$soc->fk_account:0));
|
||||
$remise_percent = (!empty($objectsrc->remise_percent)?$objectsrc->remise_percent:(!empty($soc->remise_percent)?$soc->remise_percent:0));
|
||||
$remise_percent = (!empty($objectsrc->remise_percent)?$objectsrc->remise_percent:(!empty($soc->remise_supplier_percent)?$soc->remise_supplier_percent:0));
|
||||
$remise_absolue = (!empty($objectsrc->remise_absolue)?$objectsrc->remise_absolue:(!empty($soc->remise_absolue)?$soc->remise_absolue:0));
|
||||
$dateinvoice = empty($conf->global->MAIN_AUTOFILL_DATE)?-1:'';
|
||||
|
||||
@ -1489,6 +1684,7 @@ if ($action == 'create')
|
||||
|
||||
if ($societe->id > 0)
|
||||
{
|
||||
$absolute_discount = $societe->getAvailableDiscounts('', '', 0, 1);
|
||||
print $societe->getNomUrl(1);
|
||||
print '<input type="hidden" name="socid" value="'.$societe->id.'">';
|
||||
}
|
||||
@ -1654,90 +1850,80 @@ if ($action == 'create')
|
||||
|
||||
if (empty($origin))
|
||||
{
|
||||
if ($conf->global->MAIN_FEATURES_LEVEL > 0) // Need to fix reports of standard accounting module to manage supplier credit note
|
||||
if ($societe->id > 0)
|
||||
{
|
||||
if ($societe->id > 0)
|
||||
{
|
||||
// Credit note
|
||||
if (empty($conf->global->INVOICE_DISABLE_CREDIT_NOTE))
|
||||
{
|
||||
print '<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
|
||||
$tmp='<input type="radio" id="radio_creditnote" name="type" value="2"' . (GETPOST('type') == 2 ? ' checked' : '');
|
||||
if (! $optionsav) $tmp.=' disabled';
|
||||
$tmp.= '> ';
|
||||
// Show credit note options only if we checked credit note
|
||||
print '<script type="text/javascript" language="javascript">
|
||||
jQuery(document).ready(function() {
|
||||
if (! jQuery("#radio_creditnote").is(":checked"))
|
||||
{
|
||||
jQuery("#credit_note_options").hide();
|
||||
}
|
||||
jQuery("#radio_creditnote").click(function() {
|
||||
jQuery("#credit_note_options").show();
|
||||
});
|
||||
jQuery("#radio_standard, #radio_replacement, #radio_deposit").click(function() {
|
||||
jQuery("#credit_note_options").hide();
|
||||
});
|
||||
});
|
||||
</script>';
|
||||
$text = $tmp.$langs->transnoentities("InvoiceAvoirAsk") . ' ';
|
||||
// $text.='<input type="text" value="">';
|
||||
$text .= '<select class="flat valignmiddle" name="fac_avoir" id="fac_avoir"';
|
||||
if (! $optionsav)
|
||||
$text .= ' disabled';
|
||||
$text .= '>';
|
||||
if ($optionsav) {
|
||||
$text .= '<option value="-1"></option>';
|
||||
$text .= $optionsav;
|
||||
} else {
|
||||
$text .= '<option value="-1">' . $langs->trans("NoInvoiceToCorrect") . '</option>';
|
||||
}
|
||||
$text .= '</select>';
|
||||
$desc = $form->textwithpicto($text, $langs->transnoentities("InvoiceAvoirDesc"), 1, 'help', '', 0, 3);
|
||||
print $desc;
|
||||
|
||||
print '<div id="credit_note_options" class="clearboth">';
|
||||
print ' <input type="checkbox" name="invoiceAvoirWithLines" id="invoiceAvoirWithLines" value="1" onclick="if($(this).is(\':checked\') ) { $(\'#radio_creditnote\').prop(\'checked\', true); $(\'#invoiceAvoirWithPaymentRestAmount\').removeAttr(\'checked\'); }" '.(GETPOST('invoiceAvoirWithLines','int')>0 ? 'checked':'').' /> <label for="invoiceAvoirWithLines">'.$langs->trans('invoiceAvoirWithLines')."</label>";
|
||||
print '<br> <input type="checkbox" name="invoiceAvoirWithPaymentRestAmount" id="invoiceAvoirWithPaymentRestAmount" value="1" onclick="if($(this).is(\':checked\') ) { $(\'#radio_creditnote\').prop(\'checked\', true); $(\'#invoiceAvoirWithLines\').removeAttr(\'checked\'); }" '.(GETPOST('invoiceAvoirWithPaymentRestAmount','int')>0 ? 'checked':'').' /> <label for="invoiceAvoirWithPaymentRestAmount">'.$langs->trans('invoiceAvoirWithPaymentRestAmount')."</label>";
|
||||
print '</div>';
|
||||
|
||||
print '</div></div>';
|
||||
}
|
||||
}
|
||||
else
|
||||
// Credit note
|
||||
if (empty($conf->global->INVOICE_DISABLE_CREDIT_NOTE))
|
||||
{
|
||||
print '<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
|
||||
$tmp='<input type="radio" name="type" id="radio_creditnote" value="0" disabled> ';
|
||||
$text = $tmp.$langs->trans("InvoiceAvoir") . ' ';
|
||||
$text.= '('.$langs->trans("YouMustCreateInvoiceFromSupplierThird").') ';
|
||||
$tmp='<input type="radio" id="radio_creditnote" name="type" value="2"' . (GETPOST('type') == 2 ? ' checked' : '');
|
||||
if (! $optionsav) $tmp.=' disabled';
|
||||
$tmp.= '> ';
|
||||
// Show credit note options only if we checked credit note
|
||||
print '<script type="text/javascript" language="javascript">
|
||||
jQuery(document).ready(function() {
|
||||
if (! jQuery("#radio_creditnote").is(":checked"))
|
||||
{
|
||||
jQuery("#credit_note_options").hide();
|
||||
}
|
||||
jQuery("#radio_creditnote").click(function() {
|
||||
jQuery("#credit_note_options").show();
|
||||
});
|
||||
jQuery("#radio_standard, #radio_replacement, #radio_deposit").click(function() {
|
||||
jQuery("#credit_note_options").hide();
|
||||
});
|
||||
});
|
||||
</script>';
|
||||
$text = $tmp.$langs->transnoentities("InvoiceAvoirAsk") . ' ';
|
||||
// $text.='<input type="text" value="">';
|
||||
$text .= '<select class="flat valignmiddle" name="fac_avoir" id="fac_avoir"';
|
||||
if (! $optionsav)
|
||||
$text .= ' disabled';
|
||||
$text .= '>';
|
||||
if ($optionsav) {
|
||||
$text .= '<option value="-1"></option>';
|
||||
$text .= $optionsav;
|
||||
} else {
|
||||
$text .= '<option value="-1">' . $langs->trans("NoInvoiceToCorrect") . '</option>';
|
||||
}
|
||||
$text .= '</select>';
|
||||
$desc = $form->textwithpicto($text, $langs->transnoentities("InvoiceAvoirDesc"), 1, 'help', '', 0, 3);
|
||||
print $desc;
|
||||
print '</div></div>' . "\n";
|
||||
|
||||
print '<div id="credit_note_options" class="clearboth">';
|
||||
print ' <input type="checkbox" name="invoiceAvoirWithLines" id="invoiceAvoirWithLines" value="1" onclick="if($(this).is(\':checked\') ) { $(\'#radio_creditnote\').prop(\'checked\', true); $(\'#invoiceAvoirWithPaymentRestAmount\').removeAttr(\'checked\'); }" '.(GETPOST('invoiceAvoirWithLines','int')>0 ? 'checked':'').' /> <label for="invoiceAvoirWithLines">'.$langs->trans('invoiceAvoirWithLines')."</label>";
|
||||
print '<br> <input type="checkbox" name="invoiceAvoirWithPaymentRestAmount" id="invoiceAvoirWithPaymentRestAmount" value="1" onclick="if($(this).is(\':checked\') ) { $(\'#radio_creditnote\').prop(\'checked\', true); $(\'#invoiceAvoirWithLines\').removeAttr(\'checked\'); }" '.(GETPOST('invoiceAvoirWithPaymentRestAmount','int')>0 ? 'checked':'').' /> <label for="invoiceAvoirWithPaymentRestAmount">'.$langs->trans('invoiceAvoirWithPaymentRestAmount')."</label>";
|
||||
print '</div>';
|
||||
|
||||
print '</div></div>';
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
print '<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
|
||||
$tmp='<input type="radio" name="type" id="radio_creditnote" value="0" disabled> ';
|
||||
$text = $tmp.$langs->trans("InvoiceAvoir") . ' ';
|
||||
$text.= '('.$langs->trans("YouMustCreateInvoiceFromSupplierThird").') ';
|
||||
$desc = $form->textwithpicto($text, $langs->transnoentities("InvoiceAvoirDesc"), 1, 'help', '', 0, 3);
|
||||
print $desc;
|
||||
print '</div></div>' . "\n";
|
||||
}
|
||||
}
|
||||
|
||||
print '</div>';
|
||||
|
||||
print '</td></tr>';
|
||||
|
||||
if ($socid > 0)
|
||||
if ($societe->id > 0)
|
||||
{
|
||||
// Discounts for third party
|
||||
print '<tr><td>' . $langs->trans('Discounts') . '</td><td>';
|
||||
if ($soc->remise_percent)
|
||||
print $langs->trans("CompanyHasRelativeDiscount", '<a href="' . DOL_URL_ROOT . '/comm/remise.php?id=' . $soc->id . '&backtopage=' . urlencode($_SERVER["PHP_SELF"] . '?socid=' . $soc->id . '&action=' . $action . '&origin=' . GETPOST('origin') . '&originid=' . GETPOST('originid')) . '">' . $soc->remise_percent . '</a>');
|
||||
else
|
||||
print $langs->trans("CompanyHasNoRelativeDiscount");
|
||||
print ' <a href="' . DOL_URL_ROOT . '/comm/remise.php?id=' . $soc->id . '&backtopage=' . urlencode($_SERVER["PHP_SELF"] . '?socid=' . $soc->id . '&action=' . $action . '&origin=' . GETPOST('origin') . '&originid=' . GETPOST('originid')) . '">(' . $langs->trans("EditRelativeDiscount") . ')</a>';
|
||||
print '. ';
|
||||
print '<br>';
|
||||
if ($absolute_discount)
|
||||
print $langs->trans("CompanyHasAbsoluteDiscount", '<a href="' . DOL_URL_ROOT . '/comm/remx.php?id=' . $soc->id . '&backtopage=' . urlencode($_SERVER["PHP_SELF"] . '?socid=' . $soc->id . '&action=' . $action . '&origin=' . GETPOST('origin') . '&originid=' . GETPOST('originid')) . '">' . price($absolute_discount) . '</a>', $langs->trans("Currency" . $conf->currency));
|
||||
else
|
||||
print $langs->trans("CompanyHasNoAbsoluteDiscount");
|
||||
print ' <a href="' . DOL_URL_ROOT . '/comm/remx.php?id=' . $soc->id . '&backtopage=' . urlencode($_SERVER["PHP_SELF"] . '?socid=' . $soc->id . '&action=' . $action . '&origin=' . GETPOST('origin') . '&originid=' . GETPOST('originid')) . '">(' . $langs->trans("EditGlobalDiscounts") . ')</a>';
|
||||
print '.';
|
||||
|
||||
$thirdparty = $societe;
|
||||
$discount_type = 1;
|
||||
$backtopage = urlencode($_SERVER["PHP_SELF"] . '?socid=' . $societe->id . '&action=' . $action . '&origin=' . GETPOST('origin') . '&originid=' . GETPOST('originid'));
|
||||
include DOL_DOCUMENT_ROOT.'/core/tpl/object_discounts.tpl.php';
|
||||
|
||||
print '</td></tr>';
|
||||
}
|
||||
|
||||
@ -1948,6 +2134,18 @@ else
|
||||
}
|
||||
$resteapayeraffiche = $resteapayer;
|
||||
|
||||
if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) { // Never use this
|
||||
$filterabsolutediscount = "fk_invoice_supplier_source IS NULL"; // If we want deposit to be substracted to payments only and not to total of final invoice
|
||||
$filtercreditnote = "fk_invoice_supplier_source IS NOT NULL"; // If we want deposit to be substracted to payments only and not to total of final invoice
|
||||
} else {
|
||||
$filterabsolutediscount = "fk_invoice_supplier_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS PAID)%')";
|
||||
$filtercreditnote = "fk_invoice_supplier_source IS NOT NULL AND (description NOT LIKE '(DEPOSIT)%' OR description LIKE '(EXCESS PAID)%')";
|
||||
}
|
||||
|
||||
$absolute_discount = $societe->getAvailableDiscounts('', $filterabsolutediscount, 0, 1);
|
||||
$absolute_creditnote = $societe->getAvailableDiscounts('', $filtercreditnote, 0, 1);
|
||||
$absolute_discount = price2num($absolute_discount, 'MT');
|
||||
$absolute_creditnote = price2num($absolute_creditnote, 'MT');
|
||||
|
||||
/*
|
||||
* View card
|
||||
@ -1957,6 +2155,17 @@ else
|
||||
|
||||
dol_fiche_head($head, 'card', $titre, -1, 'bill');
|
||||
|
||||
$formconfirm = '';
|
||||
|
||||
// Confirmation de la conversion de l'avoir en reduc
|
||||
if ($action == 'converttoreduc') {
|
||||
if($object->type == FactureFournisseur::TYPE_STANDARD) $type_fac = 'ExcessPaid';
|
||||
elseif($object->type == FactureFournisseur::TYPE_CREDIT_NOTE) $type_fac = 'CreditNote';
|
||||
elseif($object->type == FactureFournisseur::TYPE_DEPOSIT) $type_fac = 'Deposit';
|
||||
$text = $langs->trans('ConfirmConvertToReducSupplier', strtolower($langs->transnoentities($type_fac)));
|
||||
$formconfirm = $form->formconfirm($_SERVER['PHP_SELF'] . '?facid=' . $object->id, $langs->trans('ConvertToReduc'), $text, 'confirm_converttoreduc', '', "yes", 2);
|
||||
}
|
||||
|
||||
// Clone confirmation
|
||||
if ($action == 'clone')
|
||||
{
|
||||
@ -2192,8 +2401,27 @@ else
|
||||
$facthatreplace->fetch($facidnext);
|
||||
print ' ('.$langs->transnoentities("ReplacedByInvoice",$facthatreplace->getNomUrl(1)).')';
|
||||
}
|
||||
if ($object->type == FactureFournisseur::TYPE_CREDIT_NOTE || $object->type == FactureFournisseur::TYPE_DEPOSIT) {
|
||||
$discount = new DiscountAbsolute($db);
|
||||
$result = $discount->fetch(0, 0, $object->id);
|
||||
if ($result > 0){
|
||||
print '. '.$langs->trans("CreditNoteConvertedIntoDiscount", $object->getLibType(), $discount->getNomUrl(1, 'discount')).'<br>';
|
||||
}
|
||||
}
|
||||
print '</td></tr>';
|
||||
|
||||
|
||||
// Relative and absolute discounts
|
||||
print '<!-- Discounts --><tr><td>' . $langs->trans('Discounts');
|
||||
print '</td><td>';
|
||||
|
||||
$thirdparty = $societe;
|
||||
$discount_type = 1;
|
||||
$backtopage = urlencode($_SERVER["PHP_SELF"] . '?facid=' . $object->id);
|
||||
include DOL_DOCUMENT_ROOT.'/core/tpl/object_discounts.tpl.php';
|
||||
|
||||
print '</td></tr>';
|
||||
|
||||
// Label
|
||||
print '<tr>';
|
||||
print '<td>'.$form->editfieldkey("Label",'label',$object->label,$object,($user->rights->fournisseur->facture->creer)).'</td>';
|
||||
@ -2543,18 +2771,20 @@ else
|
||||
print $langs->trans('AlreadyPaid');
|
||||
print ' :</td><td align="right"'.(($totalpaye > 0)?' class="amountalreadypaid"':'').'>' . price($totalpaye) . '</td><td> </td></tr>';
|
||||
|
||||
$resteapayer = $object->total_ttc - $totalpaye;
|
||||
//$resteapayer = $object->total_ttc - $totalpaye;
|
||||
$resteapayeraffiche = $resteapayer;
|
||||
|
||||
$cssforamountpaymentcomplete = 'amountpaymentcomplete';
|
||||
|
||||
// Loop on each credit note or deposit amount applied
|
||||
$creditnoteamount = 0;
|
||||
$depositamount = 0;
|
||||
/*
|
||||
|
||||
|
||||
$sql = "SELECT re.rowid, re.amount_ht, re.amount_tva, re.amount_ttc,";
|
||||
$sql .= " re.description, re.fk_facture_source";
|
||||
$sql .= " FROM " . MAIN_DB_PREFIX . "societe_remise_except_supplier as re";
|
||||
$sql .= " WHERE fk_facture = " . $object->id;
|
||||
$sql .= " re.description, re.fk_invoice_supplier_source";
|
||||
$sql .= " FROM " . MAIN_DB_PREFIX . "societe_remise_except as re";
|
||||
$sql .= " WHERE fk_invoice_supplier = " . $object->id;
|
||||
$resql = $db->query($sql);
|
||||
if ($resql) {
|
||||
$num = $db->num_rows($resql);
|
||||
@ -2562,7 +2792,7 @@ else
|
||||
$invoice = new FactureFournisseur($db);
|
||||
while ($i < $num) {
|
||||
$obj = $db->fetch_object($resql);
|
||||
$invoice->fetch($obj->fk_facture_source);
|
||||
$invoice->fetch($obj->fk_invoice_supplier_source);
|
||||
print '<tr><td colspan="' . $nbcols . '" align="right">';
|
||||
if ($invoice->type == FactureFournisseur::TYPE_CREDIT_NOTE)
|
||||
print $langs->trans("CreditNote") . ' ';
|
||||
@ -2583,7 +2813,6 @@ else
|
||||
} else {
|
||||
dol_print_error($db);
|
||||
}
|
||||
*/
|
||||
|
||||
// Paye partiellement 'escompte'
|
||||
if (($object->statut == FactureFournisseur::STATUS_CLOSED || $object->statut == FactureFournisseur::STATUS_ABANDONED) && $object->close_code == 'discount_vat') {
|
||||
@ -2629,9 +2858,9 @@ else
|
||||
if ($resteapayeraffiche >= 0)
|
||||
print $langs->trans('RemainderToPay');
|
||||
else
|
||||
print $langs->trans('ExcessReceived');
|
||||
print $langs->trans('ExcessPaid');
|
||||
print ' :</td>';
|
||||
print '<td align="right"'.($resteapayeraffiche?' class="amountremaintopay"':$cssforamountpaymentcomplete).'>' . price($resteapayeraffiche) . '</td>';
|
||||
print '<td align="right" class="'.($resteapayeraffiche?'amountremaintopay':$cssforamountpaymentcomplete).'">' . price($resteapayeraffiche) . '</td>';
|
||||
print '<td class="nowrap"> </td></tr>';
|
||||
}
|
||||
else // Credit note
|
||||
@ -2653,7 +2882,7 @@ else
|
||||
else
|
||||
print $langs->trans('ExcessPaydBack');
|
||||
print ' :</td>';
|
||||
print '<td align="right"'.($resteapayeraffiche?' class="amountremaintopay"':(' class="'.$cssforamountpaymentcomplete.'"')).'>' . price($sign * $resteapayeraffiche) . '</td>';
|
||||
print '<td align="right" class="'.($resteapayeraffiche?'amountremaintopay':$cssforamountpaymentcomplete).'">' . price($sign * $resteapayeraffiche) . '</td>';
|
||||
print '<td class="nowrap"> </td></tr>';
|
||||
|
||||
// Sold credit note
|
||||
@ -2796,7 +3025,7 @@ else
|
||||
}
|
||||
|
||||
// Reverse back money or convert to reduction
|
||||
if ($object->type == FactureFournisseur::TYPE_CREDIT_NOTE || $object->type == FactureFournisseur::TYPE_DEPOSIT) {
|
||||
if ($object->type == FactureFournisseur::TYPE_CREDIT_NOTE || $object->type == FactureFournisseur::TYPE_DEPOSIT || $object->type == FactureFournisseur::TYPE_STANDARD) {
|
||||
// For credit note only
|
||||
if ($object->type == FactureFournisseur::TYPE_CREDIT_NOTE && $object->statut == 1 && $object->paye == 0)
|
||||
{
|
||||
@ -2810,6 +3039,11 @@ else
|
||||
}
|
||||
}
|
||||
|
||||
// For standard invoice with excess paid
|
||||
if ($object->type == FactureFournisseur::TYPE_STANDARD && empty($object->paye) && ($object->total_ttc - $totalpaye - $totalcreditnotes - $totaldeposits) < 0 && $user->rights->fournisseur->facture->creer && empty($discount->id))
|
||||
{
|
||||
print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?facid='.$object->id.'&action=converttoreduc">'.$langs->trans('ConvertExcessPaidToReduc').'</a></div>';
|
||||
}
|
||||
// For credit note
|
||||
if ($object->type == FactureFournisseur::TYPE_CREDIT_NOTE && $object->statut == 1 && $object->paye == 0 && $user->rights->fournisseur->facture->creer && $object->getSommePaiement() == 0) {
|
||||
print '<div class="inline-block divButAction"><a class="butAction" href="' . $_SERVER["PHP_SELF"] . '?facid=' . $object->id . '&action=converttoreduc">' . $langs->trans('ConvertToReduc') . '</a></div>';
|
||||
@ -2932,7 +3166,7 @@ else
|
||||
}
|
||||
|
||||
// Presend form
|
||||
$modelmail='supplier_order_send';
|
||||
$modelmail='invoice_supplier_send';
|
||||
$defaulttopic='SendBillRef';
|
||||
$diroutput = $conf->fournisseur->facture->dir_output;
|
||||
$trackid = 'sin'.$object->id;
|
||||
|
||||
@ -76,6 +76,7 @@ $search_amount_all_tax = GETPOST("search_amount_all_tax","alpha");
|
||||
$search_product_category=GETPOST('search_product_category','int');
|
||||
$search_ref=GETPOST('sf_ref')?GETPOST('sf_ref','alpha'):GETPOST('search_ref','alpha');
|
||||
$search_refsupplier=GETPOST('search_refsupplier','alpha');
|
||||
$search_type=GETPOST('search_type','int');
|
||||
$search_project=GETPOST('search_project','alpha');
|
||||
$search_societe=GETPOST('search_societe','alpha');
|
||||
$search_montant_ht=GETPOST('search_montant_ht','alpha');
|
||||
@ -148,6 +149,7 @@ $checkedtypetiers=0;
|
||||
$arrayfields=array(
|
||||
'f.ref'=>array('label'=>$langs->trans("Ref"), 'checked'=>1),
|
||||
'f.ref_supplier'=>array('label'=>$langs->trans("RefSupplier"), 'checked'=>1),
|
||||
'f.type'=>array('label'=>$langs->trans("Type"), 'checked'=>0),
|
||||
'f.label'=>array('label'=>$langs->trans("Label"), 'checked'=>0),
|
||||
'f.datef'=>array('label'=>$langs->trans("DateInvoice"), 'checked'=>1),
|
||||
'f.date_lim_reglement'=>array('label'=>$langs->trans("DateDue"), 'checked'=>1),
|
||||
@ -203,6 +205,7 @@ if (empty($reshook))
|
||||
$search_product_category='';
|
||||
$search_ref="";
|
||||
$search_refsupplier="";
|
||||
$search_type="";
|
||||
$search_label="";
|
||||
$search_project='';
|
||||
$search_societe="";
|
||||
@ -261,7 +264,7 @@ llxHeader('',$langs->trans("SuppliersInvoices"),'EN:Suppliers_Invoices|FR:Factur
|
||||
|
||||
$sql = "SELECT";
|
||||
if ($search_all || $search_product_category > 0) $sql = 'SELECT DISTINCT';
|
||||
$sql.= " f.rowid as facid, f.ref, f.ref_supplier, f.datef, f.date_lim_reglement as datelimite, f.fk_mode_reglement,";
|
||||
$sql.= " f.rowid as facid, f.ref, f.ref_supplier, f.type, f.datef, f.date_lim_reglement as datelimite, f.fk_mode_reglement,";
|
||||
$sql.= " f.total_ht, f.total_ttc, f.total_tva as total_vat, f.paye as paye, f.fk_statut as fk_statut, f.libelle as label, f.datec as date_creation, f.tms as date_update,";
|
||||
$sql.= " f.localtax1 as total_localtax1, f.localtax2 as total_localtax2,";
|
||||
$sql.= " s.rowid as socid, s.nom as name, s.email, s.town, s.zip, s.fk_pays, s.client, s.fournisseur, s.code_client, s.code_fournisseur, s.code_compta as code_compta_client, s.code_compta_fournisseur,";
|
||||
@ -307,6 +310,15 @@ if ($search_ref)
|
||||
}
|
||||
if ($search_ref) $sql .= natural_search('f.ref', $search_ref);
|
||||
if ($search_refsupplier) $sql .= natural_search('f.ref_supplier', $search_refsupplier);
|
||||
if ($search_type != '' && $search_type >= 0)
|
||||
{
|
||||
if ($search_type == '0') $sql.=" AND f.type = 0"; // standard
|
||||
if ($search_type == '1') $sql.=" AND f.type = 1"; // replacement
|
||||
if ($search_type == '2') $sql.=" AND f.type = 2"; // credit note
|
||||
if ($search_type == '3') $sql.=" AND f.type = 3"; // deposit
|
||||
//if ($search_type == '4') $sql.=" AND f.type = 4"; // proforma
|
||||
//if ($search_type == '5') $sql.=" AND f.type = 5"; // situation
|
||||
}
|
||||
if ($search_project) $sql .= natural_search('p.ref', $search_project);
|
||||
if ($search_societe) $sql .= natural_search('s.nom', $search_societe);
|
||||
if ($search_town) $sql.= natural_search('s.town', $search_town);
|
||||
@ -377,7 +389,7 @@ $sql.=$hookmanager->resPrint;
|
||||
|
||||
if (! $search_all)
|
||||
{
|
||||
$sql.= " GROUP BY f.rowid, f.ref, f.ref_supplier, f.datef, f.date_lim_reglement, f.fk_mode_reglement,";
|
||||
$sql.= " GROUP BY f.rowid, f.ref, f.ref_supplier, f.type, f.datef, f.date_lim_reglement, f.fk_mode_reglement,";
|
||||
$sql.= " f.total_ht, f.total_ttc, f.total_tva, f.paye, f.fk_statut, f.libelle, f.datec, f.tms,";
|
||||
$sql.= " f.localtax1, f.localtax2,";
|
||||
$sql.= ' s.rowid, s.nom, s.email, s.town, s.zip, s.fk_pays, s.client, s.fournisseur, s.code_client, s.code_fournisseur, s.code_compta, s.code_compta_fournisseur,';
|
||||
@ -434,6 +446,7 @@ if ($resql)
|
||||
if ($year_lim) $param.='&year_lim=' .urlencode($year_lim);
|
||||
if ($search_ref) $param.='&search_ref='.urlencode($search_ref);
|
||||
if ($search_refsupplier) $param.='&search_refsupplier='.urlencode($search_refsupplier);
|
||||
if ($search_type != '') $param.='&search_type='.urlencode($search_type);
|
||||
if ($search_label) $param.='&search_label='.urlencode($search_label);
|
||||
if ($search_company) $param.='&search_company='.urlencode($search_company);
|
||||
if ($search_montant_ht != '') $param.='&search_montant_ht='.urlencode($search_montant_ht);
|
||||
@ -590,6 +603,26 @@ if ($resql)
|
||||
print '<input class="flat" size="6" type="text" name="search_refsupplier" value="'.$search_refsupplier.'">';
|
||||
print '</td>';
|
||||
}
|
||||
// Type
|
||||
if (! empty($arrayfields['f.type']['checked']))
|
||||
{
|
||||
print '<td class="liste_titre maxwidthonsmartphone">';
|
||||
$listtype=array(
|
||||
FactureFournisseur::TYPE_STANDARD=>$langs->trans("InvoiceStandard"),
|
||||
FactureFournisseur::TYPE_REPLACEMENT=>$langs->trans("InvoiceReplacement"),
|
||||
FactureFournisseur::TYPE_CREDIT_NOTE=>$langs->trans("InvoiceAvoir"),
|
||||
FactureFournisseur::TYPE_DEPOSIT=>$langs->trans("InvoiceDeposit"),
|
||||
);
|
||||
/*
|
||||
if (! empty($conf->global->INVOICE_USE_SITUATION))
|
||||
{
|
||||
$listtype[Facture::TYPE_SITUATION] = $langs->trans("InvoiceSituation");
|
||||
}
|
||||
*/
|
||||
//$listtype[Facture::TYPE_PROFORMA]=$langs->trans("InvoiceProForma"); // A proformat invoice is not an invoice but must be an order.
|
||||
print $form->selectarray('search_type', $listtype, $search_type, 1, 0, 0, '', 0, 0, 0, 'ASC', 'maxwidth100');
|
||||
print '</td>';
|
||||
}
|
||||
// Label
|
||||
if (! empty($arrayfields['f.label']['checked']))
|
||||
{
|
||||
@ -741,6 +774,7 @@ if ($resql)
|
||||
print '<tr class="liste_titre">';
|
||||
if (! empty($arrayfields['f.ref']['checked'])) print_liste_field_titre($arrayfields['f.ref']['label'],$_SERVER['PHP_SELF'],'f.ref,f.rowid','',$param,'',$sortfield,$sortorder);
|
||||
if (! empty($arrayfields['f.ref_supplier']['checked'])) print_liste_field_titre($arrayfields['f.ref_supplier']['label'],$_SERVER["PHP_SELF"],'f.ref_supplier','',$param,'',$sortfield,$sortorder);
|
||||
if (! empty($arrayfields['f.type']['checked'])) print_liste_field_titre($arrayfields['f.type']['label'],$_SERVER["PHP_SELF"],'f.type','',$param,'',$sortfield,$sortorder);
|
||||
if (! empty($arrayfields['f.label']['checked'])) print_liste_field_titre($arrayfields['f.label']['label'],$_SERVER['PHP_SELF'],"f.libelle,f.rowid",'',$param,'',$sortfield,$sortorder);
|
||||
if (! empty($arrayfields['f.datef']['checked'])) print_liste_field_titre($arrayfields['f.datef']['label'],$_SERVER['PHP_SELF'],'f.datef,f.rowid','',$param,'align="center"',$sortfield,$sortorder);
|
||||
if (! empty($arrayfields['f.date_lim_reglement']['checked'])) print_liste_field_titre($arrayfields['f.date_lim_reglement']['label'],$_SERVER['PHP_SELF'],"f.date_lim_reglement",'',$param,'align="center"',$sortfield,$sortorder);
|
||||
@ -767,7 +801,7 @@ if ($resql)
|
||||
print $hookmanager->resPrint;
|
||||
if (! empty($arrayfields['f.datec']['checked'])) print_liste_field_titre($arrayfields['f.datec']['label'],$_SERVER["PHP_SELF"],"f.datec","",$param,'align="center" class="nowrap"',$sortfield,$sortorder);
|
||||
if (! empty($arrayfields['f.tms']['checked'])) print_liste_field_titre($arrayfields['f.tms']['label'],$_SERVER["PHP_SELF"],"f.tms","",$param,'align="center" class="nowrap"',$sortfield,$sortorder);
|
||||
if (! empty($arrayfields['f.fk_statut']['checked'])) print_liste_field_titre($arrayfields['f.fk_statut']['label'],$_SERVER["PHP_SELF"],"fk_statut,paye","",$param,'align="right"',$sortfield,$sortorder);
|
||||
if (! empty($arrayfields['f.fk_statut']['checked'])) print_liste_field_titre($arrayfields['f.fk_statut']['label'],$_SERVER["PHP_SELF"],"fk_statut,paye,type","",$param,'align="right"',$sortfield,$sortorder);
|
||||
print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"],"",'','','align="center"',$sortfield,$sortorder,'maxwidthsearch ');
|
||||
print "</tr>\n";
|
||||
|
||||
@ -843,6 +877,15 @@ if ($resql)
|
||||
print '</td>';
|
||||
if (! $i) $totalarray['nbfield']++;
|
||||
}
|
||||
|
||||
// Type
|
||||
if (! empty($arrayfields['f.type']['checked']))
|
||||
{
|
||||
print '<td class="nowrap">';
|
||||
print $facturestatic->getLibType();
|
||||
print "</td>";
|
||||
if (! $i) $totalarray['nbfield']++;
|
||||
}
|
||||
|
||||
// Label
|
||||
if (! empty($arrayfields['f.label']['checked']))
|
||||
|
||||
@ -0,0 +1,221 @@
|
||||
<?php
|
||||
|
||||
namespace Egulias\EmailValidator;
|
||||
|
||||
use Doctrine\Common\Lexer\AbstractLexer;
|
||||
|
||||
class EmailLexer extends AbstractLexer
|
||||
{
|
||||
//ASCII values
|
||||
const C_DEL = 127;
|
||||
const C_NUL = 0;
|
||||
const S_AT = 64;
|
||||
const S_BACKSLASH = 92;
|
||||
const S_DOT = 46;
|
||||
const S_DQUOTE = 34;
|
||||
const S_OPENPARENTHESIS = 49;
|
||||
const S_CLOSEPARENTHESIS = 261;
|
||||
const S_OPENBRACKET = 262;
|
||||
const S_CLOSEBRACKET = 263;
|
||||
const S_HYPHEN = 264;
|
||||
const S_COLON = 265;
|
||||
const S_DOUBLECOLON = 266;
|
||||
const S_SP = 267;
|
||||
const S_HTAB = 268;
|
||||
const S_CR = 269;
|
||||
const S_LF = 270;
|
||||
const S_IPV6TAG = 271;
|
||||
const S_LOWERTHAN = 272;
|
||||
const S_GREATERTHAN = 273;
|
||||
const S_COMMA = 274;
|
||||
const S_SEMICOLON = 275;
|
||||
const S_OPENQBRACKET = 276;
|
||||
const S_CLOSEQBRACKET = 277;
|
||||
const S_SLASH = 278;
|
||||
const S_EMPTY = null;
|
||||
const GENERIC = 300;
|
||||
const CRLF = 301;
|
||||
const INVALID = 302;
|
||||
const ASCII_INVALID_FROM = 127;
|
||||
const ASCII_INVALID_TO = 199;
|
||||
|
||||
/**
|
||||
* US-ASCII visible characters not valid for atext (@link http://tools.ietf.org/html/rfc5322#section-3.2.3)
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $charValue = array(
|
||||
'(' => self::S_OPENPARENTHESIS,
|
||||
')' => self::S_CLOSEPARENTHESIS,
|
||||
'<' => self::S_LOWERTHAN,
|
||||
'>' => self::S_GREATERTHAN,
|
||||
'[' => self::S_OPENBRACKET,
|
||||
']' => self::S_CLOSEBRACKET,
|
||||
':' => self::S_COLON,
|
||||
';' => self::S_SEMICOLON,
|
||||
'@' => self::S_AT,
|
||||
'\\' => self::S_BACKSLASH,
|
||||
'/' => self::S_SLASH,
|
||||
',' => self::S_COMMA,
|
||||
'.' => self::S_DOT,
|
||||
'"' => self::S_DQUOTE,
|
||||
'-' => self::S_HYPHEN,
|
||||
'::' => self::S_DOUBLECOLON,
|
||||
' ' => self::S_SP,
|
||||
"\t" => self::S_HTAB,
|
||||
"\r" => self::S_CR,
|
||||
"\n" => self::S_LF,
|
||||
"\r\n" => self::CRLF,
|
||||
'IPv6' => self::S_IPV6TAG,
|
||||
'{' => self::S_OPENQBRACKET,
|
||||
'}' => self::S_CLOSEQBRACKET,
|
||||
'' => self::S_EMPTY,
|
||||
'\0' => self::C_NUL,
|
||||
);
|
||||
|
||||
protected $hasInvalidTokens = false;
|
||||
|
||||
protected $previous;
|
||||
|
||||
public function reset()
|
||||
{
|
||||
$this->hasInvalidTokens = false;
|
||||
parent::reset();
|
||||
}
|
||||
|
||||
public function hasInvalidTokens()
|
||||
{
|
||||
return $this->hasInvalidTokens;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $type
|
||||
* @throws \UnexpectedValueException
|
||||
* @return boolean
|
||||
*/
|
||||
public function find($type)
|
||||
{
|
||||
$search = clone $this;
|
||||
$search->skipUntil($type);
|
||||
|
||||
if (!$search->lookahead) {
|
||||
throw new \UnexpectedValueException($type . ' not found');
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* getPrevious
|
||||
*
|
||||
* @return array token
|
||||
*/
|
||||
public function getPrevious()
|
||||
{
|
||||
return $this->previous;
|
||||
}
|
||||
|
||||
/**
|
||||
* moveNext
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function moveNext()
|
||||
{
|
||||
$this->previous = $this->token;
|
||||
|
||||
return parent::moveNext();
|
||||
}
|
||||
|
||||
/**
|
||||
* Lexical catchable patterns.
|
||||
*
|
||||
* @return string[]
|
||||
*/
|
||||
protected function getCatchablePatterns()
|
||||
{
|
||||
return array(
|
||||
'[a-zA-Z_]+[46]?', //ASCII and domain literal
|
||||
'[^\x00-\x7F]', //UTF-8
|
||||
'[0-9]+',
|
||||
'\r\n',
|
||||
'::',
|
||||
'\s+?',
|
||||
'.',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Lexical non-catchable patterns.
|
||||
*
|
||||
* @return string[]
|
||||
*/
|
||||
protected function getNonCatchablePatterns()
|
||||
{
|
||||
return array('[\xA0-\xff]+');
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve token type. Also processes the token value if necessary.
|
||||
*
|
||||
* @param string $value
|
||||
* @throws \InvalidArgumentException
|
||||
* @return integer
|
||||
*/
|
||||
protected function getType(&$value)
|
||||
{
|
||||
if ($this->isNullType($value)) {
|
||||
return self::C_NUL;
|
||||
}
|
||||
|
||||
if ($this->isValid($value)) {
|
||||
return $this->charValue[$value];
|
||||
}
|
||||
|
||||
if ($this->isUTF8Invalid($value)) {
|
||||
$this->hasInvalidTokens = true;
|
||||
return self::INVALID;
|
||||
}
|
||||
|
||||
return self::GENERIC;
|
||||
}
|
||||
|
||||
protected function isValid($value)
|
||||
{
|
||||
if (isset($this->charValue[$value])) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $value
|
||||
* @return bool
|
||||
*/
|
||||
protected function isNullType($value)
|
||||
{
|
||||
if ($value === "\0") {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $value
|
||||
* @return bool
|
||||
*/
|
||||
protected function isUTF8Invalid($value)
|
||||
{
|
||||
if (preg_match('/\p{Cc}+/u', $value)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
protected function getModifiers()
|
||||
{
|
||||
return 'iu';
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,104 @@
|
||||
<?php
|
||||
|
||||
namespace Egulias\EmailValidator;
|
||||
|
||||
use Egulias\EmailValidator\Exception\ExpectingATEXT;
|
||||
use Egulias\EmailValidator\Exception\NoLocalPart;
|
||||
use Egulias\EmailValidator\Parser\DomainPart;
|
||||
use Egulias\EmailValidator\Parser\LocalPart;
|
||||
use Egulias\EmailValidator\Warning\EmailTooLong;
|
||||
|
||||
/**
|
||||
* EmailParser
|
||||
*
|
||||
* @author Eduardo Gulias Davis <me@egulias.com>
|
||||
*/
|
||||
class EmailParser
|
||||
{
|
||||
const EMAIL_MAX_LENGTH = 254;
|
||||
|
||||
protected $warnings;
|
||||
protected $domainPart = '';
|
||||
protected $localPart = '';
|
||||
protected $lexer;
|
||||
protected $localPartParser;
|
||||
protected $domainPartParser;
|
||||
|
||||
public function __construct(EmailLexer $lexer)
|
||||
{
|
||||
$this->lexer = $lexer;
|
||||
$this->localPartParser = new LocalPart($this->lexer);
|
||||
$this->domainPartParser = new DomainPart($this->lexer);
|
||||
$this->warnings = new \SplObjectStorage();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $str
|
||||
* @return array
|
||||
*/
|
||||
public function parse($str)
|
||||
{
|
||||
$this->lexer->setInput($str);
|
||||
|
||||
if (!$this->hasAtToken()) {
|
||||
throw new NoLocalPart();
|
||||
}
|
||||
|
||||
|
||||
$this->localPartParser->parse($str);
|
||||
$this->domainPartParser->parse($str);
|
||||
|
||||
$this->setParts($str);
|
||||
|
||||
if ($this->lexer->hasInvalidTokens()) {
|
||||
throw new ExpectingATEXT();
|
||||
}
|
||||
|
||||
return array('local' => $this->localPart, 'domain' => $this->domainPart);
|
||||
}
|
||||
|
||||
public function getWarnings()
|
||||
{
|
||||
$localPartWarnings = $this->localPartParser->getWarnings();
|
||||
$domainPartWarnings = $this->domainPartParser->getWarnings();
|
||||
$this->warnings = array_merge($localPartWarnings, $domainPartWarnings);
|
||||
|
||||
$this->addLongEmailWarning($this->localPart, $this->domainPart);
|
||||
|
||||
return $this->warnings;
|
||||
}
|
||||
|
||||
public function getParsedDomainPart()
|
||||
{
|
||||
return $this->domainPart;
|
||||
}
|
||||
|
||||
protected function setParts($email)
|
||||
{
|
||||
$parts = explode('@', $email);
|
||||
$this->domainPart = $this->domainPartParser->getDomainPart();
|
||||
$this->localPart = $parts[0];
|
||||
}
|
||||
|
||||
protected function hasAtToken()
|
||||
{
|
||||
$this->lexer->moveNext();
|
||||
$this->lexer->moveNext();
|
||||
if ($this->lexer->token['type'] === EmailLexer::S_AT) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $localPart
|
||||
* @param string $parsedDomainPart
|
||||
*/
|
||||
protected function addLongEmailWarning($localPart, $parsedDomainPart)
|
||||
{
|
||||
if (strlen($localPart . '@' . $parsedDomainPart) > self::EMAIL_MAX_LENGTH) {
|
||||
$this->warnings[EmailTooLong::CODE] = new EmailTooLong();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
namespace Egulias\EmailValidator;
|
||||
|
||||
use Egulias\EmailValidator\Exception\InvalidEmail;
|
||||
use Egulias\EmailValidator\Validation\EmailValidation;
|
||||
|
||||
class EmailValidator
|
||||
{
|
||||
/**
|
||||
* @var EmailLexer
|
||||
*/
|
||||
private $lexer;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $warnings;
|
||||
|
||||
/**
|
||||
* @var InvalidEmail
|
||||
*/
|
||||
protected $error;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->lexer = new EmailLexer();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $email
|
||||
* @param EmailValidation $emailValidation
|
||||
* @return bool
|
||||
*/
|
||||
public function isValid($email, EmailValidation $emailValidation)
|
||||
{
|
||||
$isValid = $emailValidation->isValid($email, $this->lexer);
|
||||
$this->warnings = $emailValidation->getWarnings();
|
||||
$this->error = $emailValidation->getError();
|
||||
|
||||
return $isValid;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return boolean
|
||||
*/
|
||||
public function hasWarnings()
|
||||
{
|
||||
return !empty($this->warnings);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getWarnings()
|
||||
{
|
||||
return $this->warnings;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return InvalidEmail
|
||||
*/
|
||||
public function getError()
|
||||
{
|
||||
return $this->error;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace Egulias\EmailValidator\Exception;
|
||||
|
||||
class AtextAfterCFWS extends InvalidEmail
|
||||
{
|
||||
const CODE = 133;
|
||||
const REASON = "ATEXT found after CFWS";
|
||||
}
|
||||
@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace Egulias\EmailValidator\Exception;
|
||||
|
||||
class CRLFAtTheEnd extends InvalidEmail
|
||||
{
|
||||
const CODE = 149;
|
||||
const REASON = "CRLF at the end";
|
||||
}
|
||||
@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace Egulias\EmailValidator\Exception;
|
||||
|
||||
class CRLFX2 extends InvalidEmail
|
||||
{
|
||||
const CODE = 148;
|
||||
const REASON = "Folding whitespace CR LF found twice";
|
||||
}
|
||||
@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace Egulias\EmailValidator\Exception;
|
||||
|
||||
class CRNoLF extends InvalidEmail
|
||||
{
|
||||
const CODE = 150;
|
||||
const REASON = "Missing LF after CR";
|
||||
}
|
||||
@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace Egulias\EmailValidator\Exception;
|
||||
|
||||
class CharNotAllowed extends InvalidEmail
|
||||
{
|
||||
const CODE = 201;
|
||||
const REASON = "Non allowed character in domain";
|
||||
}
|
||||
@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace Egulias\EmailValidator\Exception;
|
||||
|
||||
class CommaInDomain extends InvalidEmail
|
||||
{
|
||||
const CODE = 200;
|
||||
const REASON = "Comma ',' is not allowed in domain part";
|
||||
}
|
||||
@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace Egulias\EmailValidator\Exception;
|
||||
|
||||
class ConsecutiveAt extends InvalidEmail
|
||||
{
|
||||
const CODE = 128;
|
||||
const REASON = "Consecutive AT";
|
||||
}
|
||||
@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace Egulias\EmailValidator\Exception;
|
||||
|
||||
class ConsecutiveDot extends InvalidEmail
|
||||
{
|
||||
const CODE = 132;
|
||||
const REASON = "Consecutive DOT";
|
||||
}
|
||||
@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace Egulias\EmailValidator\Exception;
|
||||
|
||||
class DomainHyphened extends InvalidEmail
|
||||
{
|
||||
const CODE = 144;
|
||||
const REASON = "Hyphen found in domain";
|
||||
}
|
||||
@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace Egulias\EmailValidator\Exception;
|
||||
|
||||
class DotAtEnd extends InvalidEmail
|
||||
{
|
||||
const CODE = 142;
|
||||
const REASON = "Dot at the end";
|
||||
}
|
||||
@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace Egulias\EmailValidator\Exception;
|
||||
|
||||
class DotAtStart extends InvalidEmail
|
||||
{
|
||||
const CODE = 141;
|
||||
const REASON = "Found DOT at start";
|
||||
}
|
||||
@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace Egulias\EmailValidator\Exception;
|
||||
|
||||
class ExpectingAT extends InvalidEmail
|
||||
{
|
||||
const CODE = 202;
|
||||
const REASON = "Expecting AT '@' ";
|
||||
}
|
||||
@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace Egulias\EmailValidator\Exception;
|
||||
|
||||
class ExpectingATEXT extends InvalidEmail
|
||||
{
|
||||
const CODE = 137;
|
||||
const REASON = "Expecting ATEXT";
|
||||
}
|
||||
@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace Egulias\EmailValidator\Exception;
|
||||
|
||||
class ExpectingCTEXT extends InvalidEmail
|
||||
{
|
||||
const CODE = 139;
|
||||
const REASON = "Expecting CTEXT";
|
||||
}
|
||||
@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace Egulias\EmailValidator\Exception;
|
||||
|
||||
class ExpectingDTEXT extends InvalidEmail
|
||||
{
|
||||
const CODE = 129;
|
||||
const REASON = "Expected DTEXT";
|
||||
}
|
||||
@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace Egulias\EmailValidator\Exception;
|
||||
|
||||
class ExpectingDomainLiteralClose extends InvalidEmail
|
||||
{
|
||||
const CODE = 137;
|
||||
const REASON = "Closing bracket ']' for domain literal not found";
|
||||
}
|
||||
@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace Egulias\EmailValidator\Exception;
|
||||
|
||||
class ExpectedQPair extends InvalidEmail
|
||||
{
|
||||
const CODE = 136;
|
||||
const REASON = "Expecting QPAIR";
|
||||
}
|
||||
@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace Egulias\EmailValidator\Exception;
|
||||
|
||||
abstract class InvalidEmail extends \InvalidArgumentException
|
||||
{
|
||||
const REASON = "Invalid email";
|
||||
const CODE = 0;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct(static::REASON, static::CODE);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace Egulias\EmailValidator\Exception;
|
||||
|
||||
use Egulias\EmailValidator\Exception\InvalidEmail;
|
||||
|
||||
class NoDNSRecord extends InvalidEmail
|
||||
{
|
||||
const CODE = 5;
|
||||
const REASON = 'No MX or A DSN record was found for this email';
|
||||
}
|
||||
@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace Egulias\EmailValidator\Exception;
|
||||
|
||||
class NoDomainPart extends InvalidEmail
|
||||
{
|
||||
const CODE = 131;
|
||||
const REASON = "No Domain part";
|
||||
}
|
||||
@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace Egulias\EmailValidator\Exception;
|
||||
|
||||
class NoLocalPart extends InvalidEmail
|
||||
{
|
||||
const CODE = 130;
|
||||
const REASON = "No local part";
|
||||
}
|
||||
@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace Egulias\EmailValidator\Exception;
|
||||
|
||||
class UnclosedComment extends InvalidEmail
|
||||
{
|
||||
const CODE = 146;
|
||||
const REASON = "No colosing comment token found";
|
||||
}
|
||||
@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace Egulias\EmailValidator\Exception;
|
||||
|
||||
class UnclosedQuotedString extends InvalidEmail
|
||||
{
|
||||
const CODE = 145;
|
||||
const REASON = "Unclosed quoted string";
|
||||
}
|
||||
@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace Egulias\EmailValidator\Exception;
|
||||
|
||||
class UnopenedComment extends InvalidEmail
|
||||
{
|
||||
const CODE = 152;
|
||||
const REASON = "No opening comment token found";
|
||||
}
|
||||
@ -0,0 +1,368 @@
|
||||
<?php
|
||||
|
||||
namespace Egulias\EmailValidator\Parser;
|
||||
|
||||
use Egulias\EmailValidator\EmailLexer;
|
||||
use Egulias\EmailValidator\Exception\CharNotAllowed;
|
||||
use Egulias\EmailValidator\Exception\CommaInDomain;
|
||||
use Egulias\EmailValidator\Exception\ConsecutiveAt;
|
||||
use Egulias\EmailValidator\Exception\CRLFAtTheEnd;
|
||||
use Egulias\EmailValidator\Exception\CRNoLF;
|
||||
use Egulias\EmailValidator\Exception\DomainHyphened;
|
||||
use Egulias\EmailValidator\Exception\DotAtEnd;
|
||||
use Egulias\EmailValidator\Exception\DotAtStart;
|
||||
use Egulias\EmailValidator\Exception\ExpectingATEXT;
|
||||
use Egulias\EmailValidator\Exception\ExpectingDomainLiteralClose;
|
||||
use Egulias\EmailValidator\Exception\ExpectingDTEXT;
|
||||
use Egulias\EmailValidator\Exception\NoDomainPart;
|
||||
use Egulias\EmailValidator\Exception\UnopenedComment;
|
||||
use Egulias\EmailValidator\Warning\AddressLiteral;
|
||||
use Egulias\EmailValidator\Warning\CFWSWithFWS;
|
||||
use Egulias\EmailValidator\Warning\DeprecatedComment;
|
||||
use Egulias\EmailValidator\Warning\DomainLiteral;
|
||||
use Egulias\EmailValidator\Warning\DomainTooLong;
|
||||
use Egulias\EmailValidator\Warning\IPV6BadChar;
|
||||
use Egulias\EmailValidator\Warning\IPV6ColonEnd;
|
||||
use Egulias\EmailValidator\Warning\IPV6ColonStart;
|
||||
use Egulias\EmailValidator\Warning\IPV6Deprecated;
|
||||
use Egulias\EmailValidator\Warning\IPV6DoubleColon;
|
||||
use Egulias\EmailValidator\Warning\IPV6GroupCount;
|
||||
use Egulias\EmailValidator\Warning\IPV6MaxGroups;
|
||||
use Egulias\EmailValidator\Warning\LabelTooLong;
|
||||
use Egulias\EmailValidator\Warning\ObsoleteDTEXT;
|
||||
use Egulias\EmailValidator\Warning\TLD;
|
||||
|
||||
class DomainPart extends Parser
|
||||
{
|
||||
const DOMAIN_MAX_LENGTH = 254;
|
||||
protected $domainPart = '';
|
||||
|
||||
public function parse($domainPart)
|
||||
{
|
||||
$this->lexer->moveNext();
|
||||
|
||||
if ($this->lexer->token['type'] === EmailLexer::S_DOT) {
|
||||
throw new DotAtStart();
|
||||
}
|
||||
|
||||
if ($this->lexer->token['type'] === EmailLexer::S_EMPTY) {
|
||||
throw new NoDomainPart();
|
||||
}
|
||||
if ($this->lexer->token['type'] === EmailLexer::S_HYPHEN) {
|
||||
throw new DomainHyphened();
|
||||
}
|
||||
|
||||
if ($this->lexer->token['type'] === EmailLexer::S_OPENPARENTHESIS) {
|
||||
$this->warnings[DeprecatedComment::CODE] = new DeprecatedComment();
|
||||
$this->parseDomainComments();
|
||||
}
|
||||
|
||||
$domain = $this->doParseDomainPart();
|
||||
|
||||
$prev = $this->lexer->getPrevious();
|
||||
$length = strlen($domain);
|
||||
|
||||
if ($prev['type'] === EmailLexer::S_DOT) {
|
||||
throw new DotAtEnd();
|
||||
}
|
||||
if ($prev['type'] === EmailLexer::S_HYPHEN) {
|
||||
throw new DomainHyphened();
|
||||
}
|
||||
if ($length > self::DOMAIN_MAX_LENGTH) {
|
||||
$this->warnings[DomainTooLong::CODE] = new DomainTooLong();
|
||||
}
|
||||
if ($prev['type'] === EmailLexer::S_CR) {
|
||||
throw new CRLFAtTheEnd();
|
||||
}
|
||||
$this->domainPart = $domain;
|
||||
}
|
||||
|
||||
public function getDomainPart()
|
||||
{
|
||||
return $this->domainPart;
|
||||
}
|
||||
|
||||
public function checkIPV6Tag($addressLiteral, $maxGroups = 8)
|
||||
{
|
||||
$prev = $this->lexer->getPrevious();
|
||||
if ($prev['type'] === EmailLexer::S_COLON) {
|
||||
$this->warnings[IPV6ColonEnd::CODE] = new IPV6ColonEnd();
|
||||
}
|
||||
|
||||
$IPv6 = substr($addressLiteral, 5);
|
||||
//Daniel Marschall's new IPv6 testing strategy
|
||||
$matchesIP = explode(':', $IPv6);
|
||||
$groupCount = count($matchesIP);
|
||||
$colons = strpos($IPv6, '::');
|
||||
|
||||
if (count(preg_grep('/^[0-9A-Fa-f]{0,4}$/', $matchesIP, PREG_GREP_INVERT)) !== 0) {
|
||||
$this->warnings[IPV6BadChar::CODE] = new IPV6BadChar();
|
||||
}
|
||||
|
||||
if ($colons === false) {
|
||||
// We need exactly the right number of groups
|
||||
if ($groupCount !== $maxGroups) {
|
||||
$this->warnings[IPV6GroupCount::CODE] = new IPV6GroupCount();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if ($colons !== strrpos($IPv6, '::')) {
|
||||
$this->warnings[IPV6DoubleColon::CODE] = new IPV6DoubleColon();
|
||||
return;
|
||||
}
|
||||
|
||||
if ($colons === 0 || $colons === (strlen($IPv6) - 2)) {
|
||||
// RFC 4291 allows :: at the start or end of an address
|
||||
//with 7 other groups in addition
|
||||
++$maxGroups;
|
||||
}
|
||||
|
||||
if ($groupCount > $maxGroups) {
|
||||
$this->warnings[IPV6MaxGroups::CODE] = new IPV6MaxGroups();
|
||||
} elseif ($groupCount === $maxGroups) {
|
||||
$this->warnings[IPV6Deprecated::CODE] = new IPV6Deprecated();
|
||||
}
|
||||
}
|
||||
|
||||
protected function doParseDomainPart()
|
||||
{
|
||||
$domain = '';
|
||||
$openedParenthesis = 0;
|
||||
do {
|
||||
$prev = $this->lexer->getPrevious();
|
||||
|
||||
$this->checkNotAllowedChars($this->lexer->token);
|
||||
|
||||
if ($this->lexer->token['type'] === EmailLexer::S_OPENPARENTHESIS) {
|
||||
$this->parseComments();
|
||||
$openedParenthesis += $this->getOpenedParenthesis();
|
||||
$this->lexer->moveNext();
|
||||
$tmpPrev = $this->lexer->getPrevious();
|
||||
if ($tmpPrev['type'] === EmailLexer::S_CLOSEPARENTHESIS) {
|
||||
$openedParenthesis--;
|
||||
}
|
||||
}
|
||||
if ($this->lexer->token['type'] === EmailLexer::S_CLOSEPARENTHESIS) {
|
||||
if ($openedParenthesis === 0) {
|
||||
throw new UnopenedComment();
|
||||
} else {
|
||||
$openedParenthesis--;
|
||||
}
|
||||
}
|
||||
|
||||
$this->checkConsecutiveDots();
|
||||
$this->checkDomainPartExceptions($prev);
|
||||
|
||||
if ($this->hasBrackets()) {
|
||||
$this->parseDomainLiteral();
|
||||
}
|
||||
|
||||
$this->checkLabelLength($prev);
|
||||
|
||||
if ($this->isFWS()) {
|
||||
$this->parseFWS();
|
||||
}
|
||||
|
||||
$domain .= $this->lexer->token['value'];
|
||||
$this->lexer->moveNext();
|
||||
} while ($this->lexer->token);
|
||||
|
||||
return $domain;
|
||||
}
|
||||
|
||||
private function checkNotAllowedChars($token)
|
||||
{
|
||||
$notAllowed = [EmailLexer::S_BACKSLASH => true, EmailLexer::S_SLASH=> true];
|
||||
if (isset($notAllowed[$token['type']])) {
|
||||
throw new CharNotAllowed();
|
||||
}
|
||||
}
|
||||
|
||||
protected function parseDomainLiteral()
|
||||
{
|
||||
if ($this->lexer->isNextToken(EmailLexer::S_COLON)) {
|
||||
$this->warnings[IPV6ColonStart::CODE] = new IPV6ColonStart();
|
||||
}
|
||||
if ($this->lexer->isNextToken(EmailLexer::S_IPV6TAG)) {
|
||||
$lexer = clone $this->lexer;
|
||||
$lexer->moveNext();
|
||||
if ($lexer->isNextToken(EmailLexer::S_DOUBLECOLON)) {
|
||||
$this->warnings[IPV6ColonStart::CODE] = new IPV6ColonStart();
|
||||
}
|
||||
}
|
||||
|
||||
return $this->doParseDomainLiteral();
|
||||
}
|
||||
|
||||
protected function doParseDomainLiteral()
|
||||
{
|
||||
$IPv6TAG = false;
|
||||
$addressLiteral = '';
|
||||
do {
|
||||
if ($this->lexer->token['type'] === EmailLexer::C_NUL) {
|
||||
throw new ExpectingDTEXT();
|
||||
}
|
||||
|
||||
if ($this->lexer->token['type'] === EmailLexer::INVALID ||
|
||||
$this->lexer->token['type'] === EmailLexer::C_DEL ||
|
||||
$this->lexer->token['type'] === EmailLexer::S_LF
|
||||
) {
|
||||
$this->warnings[ObsoleteDTEXT::CODE] = new ObsoleteDTEXT();
|
||||
}
|
||||
|
||||
if ($this->lexer->isNextTokenAny(array(EmailLexer::S_OPENQBRACKET, EmailLexer::S_OPENBRACKET))) {
|
||||
throw new ExpectingDTEXT();
|
||||
}
|
||||
|
||||
if ($this->lexer->isNextTokenAny(
|
||||
array(EmailLexer::S_HTAB, EmailLexer::S_SP, $this->lexer->token['type'] === EmailLexer::CRLF)
|
||||
)) {
|
||||
$this->warnings[CFWSWithFWS::CODE] = new CFWSWithFWS();
|
||||
$this->parseFWS();
|
||||
}
|
||||
|
||||
if ($this->lexer->isNextToken(EmailLexer::S_CR)) {
|
||||
throw new CRNoLF();
|
||||
}
|
||||
|
||||
if ($this->lexer->token['type'] === EmailLexer::S_BACKSLASH) {
|
||||
$this->warnings[ObsoleteDTEXT::CODE] = new ObsoleteDTEXT();
|
||||
$addressLiteral .= $this->lexer->token['value'];
|
||||
$this->lexer->moveNext();
|
||||
$this->validateQuotedPair();
|
||||
}
|
||||
if ($this->lexer->token['type'] === EmailLexer::S_IPV6TAG) {
|
||||
$IPv6TAG = true;
|
||||
}
|
||||
if ($this->lexer->token['type'] === EmailLexer::S_CLOSEQBRACKET) {
|
||||
break;
|
||||
}
|
||||
|
||||
$addressLiteral .= $this->lexer->token['value'];
|
||||
|
||||
} while ($this->lexer->moveNext());
|
||||
|
||||
$addressLiteral = str_replace('[', '', $addressLiteral);
|
||||
$addressLiteral = $this->checkIPV4Tag($addressLiteral);
|
||||
|
||||
if (false === $addressLiteral) {
|
||||
return $addressLiteral;
|
||||
}
|
||||
|
||||
if (!$IPv6TAG) {
|
||||
$this->warnings[DomainLiteral::CODE] = new DomainLiteral();
|
||||
return $addressLiteral;
|
||||
}
|
||||
|
||||
$this->warnings[AddressLiteral::CODE] = new AddressLiteral();
|
||||
|
||||
$this->checkIPV6Tag($addressLiteral);
|
||||
|
||||
return $addressLiteral;
|
||||
}
|
||||
|
||||
protected function checkIPV4Tag($addressLiteral)
|
||||
{
|
||||
$matchesIP = array();
|
||||
|
||||
// Extract IPv4 part from the end of the address-literal (if there is one)
|
||||
if (preg_match(
|
||||
'/\\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/',
|
||||
$addressLiteral,
|
||||
$matchesIP
|
||||
) > 0
|
||||
) {
|
||||
$index = strrpos($addressLiteral, $matchesIP[0]);
|
||||
if ($index === 0) {
|
||||
$this->warnings[AddressLiteral::CODE] = new AddressLiteral();
|
||||
return false;
|
||||
}
|
||||
// Convert IPv4 part to IPv6 format for further testing
|
||||
$addressLiteral = substr($addressLiteral, 0, $index) . '0:0';
|
||||
}
|
||||
|
||||
return $addressLiteral;
|
||||
}
|
||||
|
||||
protected function checkDomainPartExceptions($prev)
|
||||
{
|
||||
$invalidDomainTokens = array(
|
||||
EmailLexer::S_DQUOTE => true,
|
||||
EmailLexer::S_SEMICOLON => true,
|
||||
EmailLexer::S_GREATERTHAN => true,
|
||||
EmailLexer::S_LOWERTHAN => true,
|
||||
);
|
||||
|
||||
if (isset($invalidDomainTokens[$this->lexer->token['type']])) {
|
||||
throw new ExpectingATEXT();
|
||||
}
|
||||
|
||||
if ($this->lexer->token['type'] === EmailLexer::S_COMMA) {
|
||||
throw new CommaInDomain();
|
||||
}
|
||||
|
||||
if ($this->lexer->token['type'] === EmailLexer::S_AT) {
|
||||
throw new ConsecutiveAt();
|
||||
}
|
||||
|
||||
if ($this->lexer->token['type'] === EmailLexer::S_OPENQBRACKET && $prev['type'] !== EmailLexer::S_AT) {
|
||||
throw new ExpectingATEXT();
|
||||
}
|
||||
|
||||
if ($this->lexer->token['type'] === EmailLexer::S_HYPHEN && $this->lexer->isNextToken(EmailLexer::S_DOT)) {
|
||||
throw new DomainHyphened();
|
||||
}
|
||||
|
||||
if ($this->lexer->token['type'] === EmailLexer::S_BACKSLASH
|
||||
&& $this->lexer->isNextToken(EmailLexer::GENERIC)) {
|
||||
throw new ExpectingATEXT();
|
||||
}
|
||||
}
|
||||
|
||||
protected function hasBrackets()
|
||||
{
|
||||
if ($this->lexer->token['type'] !== EmailLexer::S_OPENBRACKET) {
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
$this->lexer->find(EmailLexer::S_CLOSEBRACKET);
|
||||
} catch (\RuntimeException $e) {
|
||||
throw new ExpectingDomainLiteralClose();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
protected function checkLabelLength($prev)
|
||||
{
|
||||
if ($this->lexer->token['type'] === EmailLexer::S_DOT &&
|
||||
$prev['type'] === EmailLexer::GENERIC &&
|
||||
strlen($prev['value']) > 63
|
||||
) {
|
||||
$this->warnings[LabelTooLong::CODE] = new LabelTooLong();
|
||||
}
|
||||
}
|
||||
|
||||
protected function parseDomainComments()
|
||||
{
|
||||
$this->isUnclosedComment();
|
||||
while (!$this->lexer->isNextToken(EmailLexer::S_CLOSEPARENTHESIS)) {
|
||||
$this->warnEscaping();
|
||||
$this->lexer->moveNext();
|
||||
}
|
||||
|
||||
$this->lexer->moveNext();
|
||||
if ($this->lexer->isNextToken(EmailLexer::S_DOT)) {
|
||||
throw new ExpectingATEXT();
|
||||
}
|
||||
}
|
||||
|
||||
protected function addTLDWarnings()
|
||||
{
|
||||
if ($this->warnings[DomainLiteral::CODE]) {
|
||||
$this->warnings[TLD::CODE] = new TLD();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,138 @@
|
||||
<?php
|
||||
|
||||
namespace Egulias\EmailValidator\Parser;
|
||||
|
||||
use Egulias\EmailValidator\Exception\DotAtEnd;
|
||||
use Egulias\EmailValidator\Exception\DotAtStart;
|
||||
use Egulias\EmailValidator\EmailLexer;
|
||||
use Egulias\EmailValidator\EmailValidator;
|
||||
use Egulias\EmailValidator\Exception\ExpectingAT;
|
||||
use Egulias\EmailValidator\Exception\ExpectingATEXT;
|
||||
use Egulias\EmailValidator\Exception\UnclosedQuotedString;
|
||||
use Egulias\EmailValidator\Exception\UnopenedComment;
|
||||
use Egulias\EmailValidator\Warning\CFWSWithFWS;
|
||||
use Egulias\EmailValidator\Warning\LocalTooLong;
|
||||
|
||||
class LocalPart extends Parser
|
||||
{
|
||||
public function parse($localPart)
|
||||
{
|
||||
$parseDQuote = true;
|
||||
$closingQuote = false;
|
||||
$openedParenthesis = 0;
|
||||
|
||||
while ($this->lexer->token['type'] !== EmailLexer::S_AT && $this->lexer->token) {
|
||||
if ($this->lexer->token['type'] === EmailLexer::S_DOT && !$this->lexer->getPrevious()) {
|
||||
throw new DotAtStart();
|
||||
}
|
||||
|
||||
$closingQuote = $this->checkDQUOTE($closingQuote);
|
||||
if ($closingQuote && $parseDQuote) {
|
||||
$parseDQuote = $this->parseDoubleQuote();
|
||||
}
|
||||
|
||||
if ($this->lexer->token['type'] === EmailLexer::S_OPENPARENTHESIS) {
|
||||
$this->parseComments();
|
||||
$openedParenthesis += $this->getOpenedParenthesis();
|
||||
}
|
||||
if ($this->lexer->token['type'] === EmailLexer::S_CLOSEPARENTHESIS) {
|
||||
if ($openedParenthesis === 0) {
|
||||
throw new UnopenedComment();
|
||||
} else {
|
||||
$openedParenthesis--;
|
||||
}
|
||||
}
|
||||
|
||||
$this->checkConsecutiveDots();
|
||||
|
||||
if ($this->lexer->token['type'] === EmailLexer::S_DOT &&
|
||||
$this->lexer->isNextToken(EmailLexer::S_AT)
|
||||
) {
|
||||
throw new DotAtEnd();
|
||||
}
|
||||
|
||||
$this->warnEscaping();
|
||||
$this->isInvalidToken($this->lexer->token, $closingQuote);
|
||||
|
||||
if ($this->isFWS()) {
|
||||
$this->parseFWS();
|
||||
}
|
||||
|
||||
$this->lexer->moveNext();
|
||||
}
|
||||
|
||||
$prev = $this->lexer->getPrevious();
|
||||
if (strlen($prev['value']) > LocalTooLong::LOCAL_PART_LENGTH) {
|
||||
$this->warnings[LocalTooLong::CODE] = new LocalTooLong();
|
||||
}
|
||||
}
|
||||
|
||||
protected function parseDoubleQuote()
|
||||
{
|
||||
$parseAgain = true;
|
||||
$special = array(
|
||||
EmailLexer::S_CR => true,
|
||||
EmailLexer::S_HTAB => true,
|
||||
EmailLexer::S_LF => true
|
||||
);
|
||||
|
||||
$invalid = array(
|
||||
EmailLexer::C_NUL => true,
|
||||
EmailLexer::S_HTAB => true,
|
||||
EmailLexer::S_CR => true,
|
||||
EmailLexer::S_LF => true
|
||||
);
|
||||
$setSpecialsWarning = true;
|
||||
|
||||
$this->lexer->moveNext();
|
||||
|
||||
while ($this->lexer->token['type'] !== EmailLexer::S_DQUOTE && $this->lexer->token) {
|
||||
$parseAgain = false;
|
||||
if (isset($special[$this->lexer->token['type']]) && $setSpecialsWarning) {
|
||||
$this->warnings[CFWSWithFWS::CODE] = new CFWSWithFWS();
|
||||
$setSpecialsWarning = false;
|
||||
}
|
||||
if ($this->lexer->token['type'] === EmailLexer::S_BACKSLASH && $this->lexer->isNextToken(EmailLexer::S_DQUOTE)) {
|
||||
$this->lexer->moveNext();
|
||||
}
|
||||
|
||||
$this->lexer->moveNext();
|
||||
|
||||
if (!$this->escaped() && isset($invalid[$this->lexer->token['type']])) {
|
||||
throw new ExpectingATEXT();
|
||||
}
|
||||
}
|
||||
|
||||
$prev = $this->lexer->getPrevious();
|
||||
|
||||
if ($prev['type'] === EmailLexer::S_BACKSLASH) {
|
||||
if (!$this->checkDQUOTE(false)) {
|
||||
throw new UnclosedQuotedString();
|
||||
}
|
||||
}
|
||||
|
||||
if (!$this->lexer->isNextToken(EmailLexer::S_AT) && $prev['type'] !== EmailLexer::S_BACKSLASH) {
|
||||
throw new ExpectingAT();
|
||||
}
|
||||
|
||||
return $parseAgain;
|
||||
}
|
||||
|
||||
protected function isInvalidToken($token, $closingQuote)
|
||||
{
|
||||
$forbidden = array(
|
||||
EmailLexer::S_COMMA,
|
||||
EmailLexer::S_CLOSEBRACKET,
|
||||
EmailLexer::S_OPENBRACKET,
|
||||
EmailLexer::S_GREATERTHAN,
|
||||
EmailLexer::S_LOWERTHAN,
|
||||
EmailLexer::S_COLON,
|
||||
EmailLexer::S_SEMICOLON,
|
||||
EmailLexer::INVALID
|
||||
);
|
||||
|
||||
if (in_array($token['type'], $forbidden) && !$closingQuote) {
|
||||
throw new ExpectingATEXT();
|
||||
}
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user