Skip to content
Snippets Groups Projects
Commit 61bc8fc9 authored by Laurent Destailleur's avatar Laurent Destailleur
Browse files

NEW Can edit value date of a vat payment after recording it.

Conflicts:
	htdocs/compta/localtax/card.php
	htdocs/core/class/html.form.class.php
parent aa9a39ca
Branches
Tags
No related merge requests found
......@@ -19,7 +19,7 @@
/**
* \file htdocs/compta/localtax/card.php
* \ingroup tax
* \brief Page of IRPF payments
* \brief Page of second or third tax payments (like IRPF for spain, ...)
*/
require '../../main.inc.php';
......@@ -30,17 +30,25 @@ $langs->load("compta");
$langs->load("banks");
$langs->load("bills");
$id=$_REQUEST["id"];
$id=GETPOST("id",'int');
$action=GETPOST("action","alpha");
$refund=GETPOST("refund","int");
if (empty($refund)) $refund=0;
$lttype=GETPOST('localTaxType', 'int');
$mesg = '';
// Security check
$socid = isset($_GET["socid"])?$_GET["socid"]:'';
if ($user->societe_id) $socid=$user->societe_id;
$result = restrictedArea($user, 'tax', '', '', 'charges');
$localtax = new Localtax($db);
/*
// Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array
$hookmanager->initHooks(array('localtaxvatcard','globalcard'));
/**
* Actions
*/
......@@ -50,9 +58,8 @@ if($_POST["cancel"] == $langs->trans("Cancel")){
exit;
}
if ($_POST["action"] == 'add' && $_POST["cancel"] <> $langs->trans("Cancel"))
if ($action == 'add' && $_POST["cancel"] <> $langs->trans("Cancel"))
{
$localtax = new Localtax($db);
$db->begin();
......@@ -83,10 +90,9 @@ if ($_POST["action"] == 'add' && $_POST["cancel"] <> $langs->trans("Cancel"))
}
//delete payment of localtax
if ($_GET["action"] == 'delete')
if ($action == 'delete')
{
$localtax = new Localtax($db);
$result=$localtax->fetch($_GET['id']);
$result=$localtax->fetch($id);
if ($localtax->rappro == 0)
{
......@@ -99,10 +105,10 @@ if ($_GET["action"] == 'delete')
{
$accountline=new AccountLine($db);
$result=$accountline->fetch($localtax->fk_bank);
$result=$accountline->delete($user);
if ($result > 0) $result=$accountline->delete($user); // $result may be 0 if not found (when bank entry was deleted manually and fk_bank point to nothing)
}
if ($result > 0)
if ($result >= 0)
{
$db->commit();
header("Location: ".DOL_URL_ROOT.'/compta/localtax/reglement.php?localTaxType='.$localtax->ltt);
......@@ -149,26 +155,26 @@ if ($id)
}
if ($_GET["action"] == 'create')
if ($action == 'create')
{
print "<form name='add' action=\"card.php\" method=\"post\">\n";
print load_fiche_titre($langs->transcountry($lttype==2?"newLT2Payment":"newLT1Payment",$mysoc->country_code));
print '<form name="add" action="'.$_SERVER["PHP_SELF"].'" name="formlocaltax" method="post">'."\n";
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<input type="hidden" name="localTaxType" value="'.$lttype.'">';
print '<input type="hidden" name="action" value="add">';
print load_fiche_titre($langs->transcountry($lttype==2?"newLT2Payment":"newLT1Payment",$mysoc->country_code));
if ($mesg) print $mesg;
dol_fiche_head();
print '<table class="border" width="100%">';
print "<tr>";
print '<td class="fieldrequired">'.$langs->trans("DatePayment").'</td><td>';
print $form->select_date($datep,"datep",'','','','add');
print $form->select_date($datep,"datep",'','','','add',1,1);
print '</td></tr>';
print '<tr><td class="fieldrequired">'.$langs->trans("DateValue").'</td><td>';
print $form->select_date($datev,"datev",'','','','add');
print $form->select_date($datev,"datev",'','','','add',1,1);
print '</td></tr>';
// Label
......@@ -184,13 +190,22 @@ if ($_GET["action"] == 'create')
print '</td></tr>';
print '<tr><td class="fieldrequired">'.$langs->trans("PaymentMode").'</td><td>';
$form->select_types_paiements($_POST["paiementtype"], "paiementtype");
$form->select_types_paiements(GETPOST("paiementtype"), "paiementtype");
print "</td>\n";
print "</tr>";
// Number
print '<tr><td>'.$langs->trans('Numero');
print ' <em>('.$langs->trans("ChequeOrTransferNumber").')</em>';
print '<td><input name="num_payment" type="text" value="'.GETPOST("num_payment").'"></td></tr>'."\n";
}
// Other attributes
$parameters=array('colspan' => ' colspan="1"');
$reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook
print '</table>';
print "<br>";
dol_fiche_end();
print '<div class="center">';
print '<input type="submit" class="button" value="'.$langs->trans("Save").'">';
......@@ -210,8 +225,6 @@ if ($_GET["action"] == 'create')
if ($id)
{
if ($mesg) print $mesg;
$h = 0;
$head[$h][0] = DOL_URL_ROOT.'/compta/localtax/card.php?id='.$vatpayment->id;
$head[$h][1] = $langs->trans('Card');
......@@ -255,9 +268,14 @@ if ($id)
}
}
// Other attributes
$parameters=array('colspan' => ' colspan="3"');
$reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$vatpayment,$action); // Note that $action and $object may have been modified by hook
print '</table>';
print '</div>';
dol_fiche_end();
/*
* Boutons d'actions
......
......
......@@ -42,7 +42,7 @@ $socid = isset($_GET["socid"])?$_GET["socid"]:'';
if ($user->societe_id) $socid=$user->societe_id;
$result = restrictedArea($user, 'tax', '', '', 'charges');
$tva = new Tva($db);
$object = new Tva($db);
// Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array
$hookmanager->initHooks(array('taxvatcard','globalcard'));
......@@ -52,12 +52,22 @@ $hookmanager->initHooks(array('taxvatcard','globalcard'));
* Actions
*/
if ($_POST["cancel"] == $langs->trans("Cancel"))
if ($_POST["cancel"] == $langs->trans("Cancel") && ! $id)
{
header("Location: reglement.php");
exit;
}
if ($action == 'setdatev' && $user->rights->tax->charges->creer)
{
$object->fetch($id);
$object->datev=dol_mktime(12,0,0,$_POST['datevmonth'],$_POST['datevday'],$_POST['datevyear']);
$result=$object->update($user);
if ($result < 0) dol_print_error($db,$object->error);
$action='';
}
if ($action == 'add' && $_POST["cancel"] <> $langs->trans("Cancel"))
{
$error=0;
......@@ -65,36 +75,36 @@ if ($action == 'add' && $_POST["cancel"] <> $langs->trans("Cancel"))
$datev=dol_mktime(12,0,0, $_POST["datevmonth"], $_POST["datevday"], $_POST["datevyear"]);
$datep=dol_mktime(12,0,0, $_POST["datepmonth"], $_POST["datepday"], $_POST["datepyear"]);
$tva->accountid=GETPOST("accountid");
$tva->type_payment=GETPOST("type_payment");
$tva->num_payment=GETPOST("num_payment");
$tva->datev=$datev;
$tva->datep=$datep;
$object->accountid=GETPOST("accountid");
$object->type_payment=GETPOST("type_payment");
$object->num_payment=GETPOST("num_payment");
$object->datev=$datev;
$object->datep=$datep;
$amount = price2num(GETPOST("amount"));
if ($refund == 1) {
$amount= -$amount;
}
$tva->amount= $amount;
$tva->label=GETPOST("label");
$tva->note=GETPOST("note");
$object->amount= $amount;
$object->label=GETPOST("label");
$object->note=GETPOST("note");
if (empty($tva->datev))
if (empty($object->datev))
{
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("DateValue")), null, 'errors');
$error++;
}
if (empty($tva->datep))
if (empty($object->datep))
{
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("DatePayment")), null, 'errors');
$error++;
}
if (empty($tva->type_payment) || $tva->type_payment < 0)
if (empty($object->type_payment) || $object->type_payment < 0)
{
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("PaymentMode")), null, 'errors');
$error++;
}
if (empty($tva->amount))
if (empty($object->amount))
{
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Amount")), null, 'errors');
$error++;
......@@ -104,7 +114,7 @@ if ($action == 'add' && $_POST["cancel"] <> $langs->trans("Cancel"))
{
$db->begin();
$ret=$tva->addPayment($user);
$ret=$object->addPayment($user);
if ($ret > 0)
{
$db->commit();
......@@ -114,7 +124,7 @@ if ($action == 'add' && $_POST["cancel"] <> $langs->trans("Cancel"))
else
{
$db->rollback();
setEventMessages($tva->error, $tva->errors, 'errors');
setEventMessages($object->error, $object->errors, 'errors');
$action="create";
}
}
......@@ -124,19 +134,19 @@ if ($action == 'add' && $_POST["cancel"] <> $langs->trans("Cancel"))
if ($action == 'delete')
{
$result=$tva->fetch($id);
$result=$object->fetch($id);
if ($tva->rappro == 0)
if ($object->rappro == 0)
{
$db->begin();
$ret=$tva->delete($user);
$ret=$object->delete($user);
if ($ret > 0)
{
if ($tva->fk_bank)
if ($object->fk_bank)
{
$accountline=new AccountLine($db);
$result=$accountline->fetch($tva->fk_bank);
$result=$accountline->fetch($object->fk_bank);
if ($result > 0) $result=$accountline->delete($user); // $result may be 0 if not found (when bank entry was deleted manually and fk_bank point to nothing)
}
......@@ -148,15 +158,15 @@ if ($action == 'delete')
}
else
{
$tva->error=$accountline->error;
$object->error=$accountline->error;
$db->rollback();
setEventMessages($tva->error, $tva->errors, 'errors');
setEventMessages($object->error, $object->errors, 'errors');
}
}
else
{
$db->rollback();
setEventMessages($tva->error, $tva->errors, 'errors');
setEventMessages($object->error, $object->errors, 'errors');
}
}
else
......@@ -176,8 +186,7 @@ $form = new Form($db);
if ($id)
{
$vatpayment = new Tva($db);
$result = $vatpayment->fetch($id);
$result = $object->fetch($id);
if ($result <= 0)
{
dol_print_error($db);
......@@ -297,7 +306,7 @@ if ($action == 'create')
if ($id)
{
$h = 0;
$head[$h][0] = DOL_URL_ROOT.'/compta/tva/card.php?id='.$vatpayment->id;
$head[$h][0] = DOL_URL_ROOT.'/compta/tva/card.php?id='.$object->id;
$head[$h][1] = $langs->trans('Card');
$head[$h][2] = 'card';
$h++;
......@@ -309,29 +318,33 @@ if ($id)
print "<tr>";
print '<td width="25%">'.$langs->trans("Ref").'</td><td colspan="3">';
print $vatpayment->ref;
print $object->ref;
print '</td></tr>';
// Label
print '<tr><td>'.$langs->trans("Label").'</td><td>'.$vatpayment->label.'</td></tr>';
print '<tr><td>'.$langs->trans("Label").'</td><td>'.$object->label.'</td></tr>';
print "<tr>";
print '<td>'.$langs->trans("DatePayment").'</td><td colspan="3">';
print dol_print_date($vatpayment->datep,'day');
print dol_print_date($object->datep,'day');
print '</td></tr>';
print '<tr><td>'.$langs->trans("DateValue").'</td><td colspan="3">';
print dol_print_date($vatpayment->datev,'day');
print '<tr><td>';
print $form->editfieldkey("DateValue", 'datev', $object->datev, $object, $user->rights->tax->charges->creer, 'day');
print '</td><td colspan="3">';
print $form->editfieldval("DateValue", 'datev', $object->datev, $object, $user->rights->tax->charges->creer, 'day');
//print dol_print_date($object->datev,'day');
print '</td></tr>';
print '<tr><td>'.$langs->trans("Amount").'</td><td colspan="3">'.price($vatpayment->amount).'</td></tr>';
print '<tr><td>'.$langs->trans("Amount").'</td><td colspan="3">'.price($object->amount).'</td></tr>';
if (! empty($conf->banque->enabled))
{
if ($vatpayment->fk_account > 0)
if ($object->fk_account > 0)
{
$bankline=new AccountLine($db);
$bankline->fetch($vatpayment->fk_bank);
$bankline->fetch($object->fk_bank);
print '<tr>';
print '<td>'.$langs->trans('BankTransactionLine').'</td>';
......@@ -344,21 +357,22 @@ if ($id)
// Other attributes
$parameters=array('colspan' => ' colspan="3"');
$reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$vatpayment,$action); // Note that $action and $object may have been modified by hook
$reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook
print '</table>';
print '</div>';
dol_fiche_end();
/*
* Boutons d'actions
*/
print "<div class=\"tabsAction\">\n";
if ($vatpayment->rappro == 0)
if ($object->rappro == 0)
{
if (! empty($user->rights->tax->charges->supprimer))
{
print '<a class="butActionDelete" href="card.php?id='.$vatpayment->id.'&action=delete">'.$langs->trans("Delete").'</a>';
print '<a class="butActionDelete" href="card.php?id='.$object->id.'&action=delete">'.$langs->trans("Delete").'</a>';
}
else
{
......
......
<?php
/* Copyright (C) 2001-2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004-2015 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2004-2016 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2005-2009 Regis Houssin <regis.houssin@capnetworks.com>
* Copyright (C) 2011-2014 Alexandre Spangaro <aspangaro.dolibarr@gmail.com>
*
......@@ -91,7 +91,7 @@ $form = new Form($db);
$formother=new FormOther($db);
$tva_static = new Tva($db);
$sql = "SELECT t.rowid, t.amount, t.label, t.datev as dm, t.fk_typepayment as type, t.num_payment, pst.code as payment_code";
$sql = "SELECT t.rowid, t.amount, t.label, t.datev as dv, t.datep as dp, t.fk_typepayment as type, t.num_payment, pst.code as payment_code";
$sql.= " FROM ".MAIN_DB_PREFIX."tva as t";
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as pst ON t.fk_typepayment = pst.id";
$sql.= " WHERE t.entity = ".$conf->entity;
......@@ -151,7 +151,8 @@ if ($result)
print '<tr class="liste_titre">';
print_liste_field_titre($langs->trans("Ref"),$_SERVER["PHP_SELF"],"t.rowid","",$param,"",$sortfield,$sortorder);
print_liste_field_titre($langs->trans("Label"),$_SERVER["PHP_SELF"],"t.label","",$param,'align="left"',$sortfield,$sortorder);
print_liste_field_titre($langs->trans("DatePayment"),$_SERVER["PHP_SELF"],"dm","",$param,'align="center"',$sortfield,$sortorder);
print_liste_field_titre($langs->trans("DateValue"),$_SERVER["PHP_SELF"],"dv","",$param,'align="center"',$sortfield,$sortorder);
print_liste_field_titre($langs->trans("DatePayment"),$_SERVER["PHP_SELF"],"dp","",$param,'align="center"',$sortfield,$sortorder);
print_liste_field_titre($langs->trans("Type"),$_SERVER["PHP_SELF"],"type","",$param,'align="left"',$sortfield,$sortorder);
print_liste_field_titre($langs->trans("PayedByThisPayment"),$_SERVER["PHP_SELF"],"t.amount","",$param,'align="right"',$sortfield,$sortorder);
print_liste_field_titre('',$_SERVER["PHP_SELF"],"",'','','',$sortfield,$sortorder,'maxwidthsearch ');
......@@ -160,6 +161,7 @@ if ($result)
print '<tr class="liste_titre">';
print '<td class="liste_titre"><input type="text" class="flat" size="4" name="search_ref" value="'.$search_ref.'"></td>';
print '<td class="liste_titre"><input type="text" class="flat" size="10" name="search_label" value="'.$search_label.'"></td>';
print '<td class="liste_titre"></td>';
print '<td class="liste_titre" colspan="1" align="center">';
print '<input class="flat" type="text" size="1" maxlength="2" name="month" value="'.$month.'">';
$syear = $year;
......@@ -197,7 +199,8 @@ if ($result)
$tva_static->ref=$obj->rowid;
print "<td>".$tva_static->getNomUrl(1)."</td>\n";
print "<td>".dol_trunc($obj->label,40)."</td>\n";
print '<td align="center">'.dol_print_date($db->jdate($obj->dm),'day')."</td>\n";
print '<td align="center">'.dol_print_date($db->jdate($obj->dv),'day')."</td>\n";
print '<td align="center">'.dol_print_date($db->jdate($obj->dp),'day')."</td>\n";
// Type
print $type;
// Amount
......
......
......@@ -74,14 +74,15 @@ class Form
*
* @param string $text Text of label or key to translate
* @param string $htmlname Name of select field ('edit' prefix will be added)
* @param string $preselected Name of Value to show/edit (not used in this function)
* @param string $value Value to show/edit (not used in this function)
* @param object $object Object
* @param boolean $perm Permission to allow button to edit parameter. Set it to 0 to have a not edited field.
* @param string $typeofdata Type of data ('string' by default, 'email', 'amount:99', 'numeric:99', 'text' or 'textarea:rows:cols', 'day' or 'datepicker', 'ckeditor:dolibarr_zzz:width:height:savemethod:1:rows:cols', 'select;xxx[:class]'...)
* @param string $moreparam More param to add on a href URL
* @param string $moreparam More param to add on a href URL*
* @param int $fieldrequired 1 if we want to show field as mandatory using the fieldrequired CSS.
* @return string HTML edit field
*/
function editfieldkey($text, $htmlname, $preselected, $object, $perm, $typeofdata='string', $moreparam='')
function editfieldkey($text, $htmlname, $preselected, $object, $perm, $typeofdata='string', $moreparam='', $fieldrequired=0)
{
global $conf,$langs;
......@@ -94,18 +95,24 @@ class Form
{
$tmp=explode(':',$typeofdata);
$ret.= '<div class="editkey_'.$tmp[0].(! empty($tmp[1]) ? ' '.$tmp[1] : '').'" id="'.$htmlname.'">';
if ($fieldrequired) $ret.='<span class="fieldrequired">';
$ret.= $langs->trans($text);
if ($fieldrequired) $ret.='</span>';
$ret.= '</div>'."\n";
}
else
{
if ($fieldrequired) $ret.='<span class="fieldrequired">';
$ret.= $langs->trans($text);
if ($fieldrequired) $ret.='</span>';
}
}
else
{
if (GETPOST('action') != 'edit'.$htmlname && $perm) $ret.='<table class="nobordernopadding" width="100%"><tr><td class="nowrap">';
if ($fieldrequired) $ret.='<span class="fieldrequired">';
$ret.=$langs->trans($text);
if ($fieldrequired) $ret.='</span>';
if (GETPOST('action') != 'edit'.$htmlname && $perm) $ret.='</td>';
if (GETPOST('action') != 'edit'.$htmlname && $perm) $ret.='<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=edit'.$htmlname.'&amp;id='.$object->id.$moreparam.'">'.img_edit($langs->trans('Edit'),1).'</a></td>';
if (GETPOST('action') != 'edit'.$htmlname && $perm) $ret.='</tr></table>';
......@@ -195,14 +202,13 @@ class Form
$ret.=$doleditor->Create(1);
}
$ret.='</td>';
//if ($typeofdata != 'day' && $typeofdata != 'dayhour' && $typeofdata != 'datepicker' && $typeofdata != 'datehourpicker')
//{
$ret.='<td align="left">';
$ret.='<input type="submit" class="button" name="modify" value="'.$langs->trans("Modify").'">';
if (preg_match('/ckeditor|textarea/',$typeofdata)) $ret.='<br>'."\n";
$ret.='<input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'">';
$ret.='</td>';
//}
$ret.='</tr></table>'."\n";
$ret.='</form>'."\n";
}
......
......
......@@ -958,6 +958,7 @@ function dol_banner_tab($object, $paramid, $morehtml='', $shownav=1, $fieldid='r
* @param string $langkey Translation key
* @param string $fieldkey Key of the html select field the text refers to
* @param int $fieldrequired 1=Field is mandatory
* @deprecated Form::editfieldkey
*/
function fieldLabel($langkey, $fieldkey, $fieldrequired=0)
{
......
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment