From 7f21e596dd7b573a69fa1594db4ff922c231e917 Mon Sep 17 00:00:00 2001 From: simnandez <jmenent@2byte.es> Date: Tue, 17 Sep 2013 17:17:59 +0200 Subject: [PATCH] [ task #1063 ] Allow edit localtaxes rate for thirds. Init Works --- htdocs/core/lib/company.lib.php | 10 + .../install/mysql/tables/llx_soc_localtaxes | 26 ++ .../mysql/tables/llx_soc_localtaxes.key.sql | 22 ++ htdocs/societe/localtaxes.php | 264 ++++++++++++++++++ 4 files changed, 322 insertions(+) create mode 100644 htdocs/install/mysql/tables/llx_soc_localtaxes create mode 100644 htdocs/install/mysql/tables/llx_soc_localtaxes.key.sql create mode 100644 htdocs/societe/localtaxes.php diff --git a/htdocs/core/lib/company.lib.php b/htdocs/core/lib/company.lib.php index 2bd863b263f..413c8d1dca8 100644 --- a/htdocs/core/lib/company.lib.php +++ b/htdocs/core/lib/company.lib.php @@ -4,6 +4,7 @@ * Copyright (C) 2007 Patrick Raguin <patrick.raguin@gmail.com> * Copyright (C) 2010-2012 Regis Houssin <regis.houssin@capnetworks.com> * Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro> + * Copyright (C) 2013 Juanjo Menent <jmenent@2byte.es> * * 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,6 +61,15 @@ function societe_prepare_head($object) $head[$h][2] = 'supplier'; $h++; } + + if (($object->localtax1_assuj || $object->localtax2_assuj) && (isset($conf->global->MAIN_FEATURES_LEVEL) && $conf->global->MAIN_FEATURES_LEVEL > 0) ) + { + $head[$h][0] = DOL_URL_ROOT.'/societe/localtaxes.php?socid='.$object->id; + $head[$h][1] = $langs->trans("LocalTaxes"); + $head[$h][2] = 'localtaxes'; + $h++; + } + if (! empty($conf->agenda->enabled) && (!empty($user->rights->agenda->myactions->read) || !empty($user->rights->agenda->allactions->read) )) { $head[$h][0] = DOL_URL_ROOT.'/societe/agenda.php?socid='.$object->id; diff --git a/htdocs/install/mysql/tables/llx_soc_localtaxes b/htdocs/install/mysql/tables/llx_soc_localtaxes new file mode 100644 index 00000000000..9293562d916 --- /dev/null +++ b/htdocs/install/mysql/tables/llx_soc_localtaxes @@ -0,0 +1,26 @@ +-- ============================================================================ +-- Copyright (C) 2013 Juanjo Menent <regis.houssin@capnetworks.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 +-- 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/>. +-- +-- =========================================================================== + +create table llx_soc_localtaxes +( + rowid integer AUTO_INCREMENT PRIMARY KEY, + fk_soc integer, + fk_tva integer, + localtax1_tx double(6,3) DEFAULT 0, -- localtax1 rate + localtax2_tx double(6,3) DEFAULT 0, -- localtax2 rate + )ENGINE=innodb; \ No newline at end of file diff --git a/htdocs/install/mysql/tables/llx_soc_localtaxes.key.sql b/htdocs/install/mysql/tables/llx_soc_localtaxes.key.sql new file mode 100644 index 00000000000..e0a5cdc2c45 --- /dev/null +++ b/htdocs/install/mysql/tables/llx_soc_localtaxes.key.sql @@ -0,0 +1,22 @@ +-- ============================================================================ +-- Copyright (C) 2013 Juanjo Menent <jmenent@2byte.es> +-- +-- 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/>. +-- +-- ============================================================================ + + +ALTER TABLE llx_soc_localtax ADD UNIQUE INDEX uk_soc_localtax_tax (fk_soc, fk_tax); + +ALTER TABLE llx_propal ADD INDEX idx_soc_localtax_fk_soc (fk_soc); diff --git a/htdocs/societe/localtaxes.php b/htdocs/societe/localtaxes.php new file mode 100644 index 00000000000..22d41484720 --- /dev/null +++ b/htdocs/societe/localtaxes.php @@ -0,0 +1,264 @@ +<?php +/* Copyright (C) 2013 Juanjo Menent <jmenent@2byte.es> + * + * 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/societe/agenda.php + * \ingroup societe + * \brief Page of third party events + */ + +require '../main.inc.php'; +require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php'; +require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php'; + +$langs->load("companies"); + +// Security check +$socid = GETPOST('socid','int'); +$vatid = GETPOST('vatid','int'); +$action = GETPOST('action','alpha'); + +if ($user->societe_id) $socid=$user->societe_id; +$result = restrictedArea($user, 'societe', $socid, '&societe'); + +// Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array +$hookmanager->initHooks(array('localtaxesthirdparty')); + + +/* + * Actions + */ + +$parameters=array('id'=>$socid); +$reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks +$error=$hookmanager->error; $errors=array_merge($errors, (array) $hookmanager->errors); + +/* + * View + */ + +$contactstatic = new Contact($db); + +$form = new Form($db); + +/* + * Fiche categorie de client et/ou fournisseur + */ +if ($socid) +{ + require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php'; + require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php'; + + $langs->load("companies"); + + + $soc = new Societe($db); + $result = $soc->fetch($socid); + llxHeader("",$langs->trans("LocalTaxes"),''); + + if (! empty($conf->notification->enabled)) $langs->load("mails"); + $head = societe_prepare_head($soc); + + dol_fiche_head($head, 'localtaxes', $langs->trans("ThirdParty"),0,'company'); + + print '<table class="border" width="100%">'; + + print '<tr><td width="25%">'.$langs->trans("ThirdPartyName").'</td><td colspan="3">'; + print $form->showrefnav($soc,'socid','',($user->societe_id?0:1),'rowid','nom'); + print '</td></tr>'; + + if (! empty($conf->global->SOCIETE_USEPREFIX)) // Old not used prefix field + { + print '<tr><td>'.$langs->trans('Prefix').'</td><td colspan="3">'.$soc->prefix_comm.'</td></tr>'; + } + + if ($soc->client) + { + print '<tr><td>'; + print $langs->trans('CustomerCode').'</td><td colspan="3">'; + print $soc->code_client; + if ($soc->check_codeclient() <> 0) print ' <font class="error">('.$langs->trans("WrongCustomerCode").')</font>'; + print '</td></tr>'; + } + + if ($soc->fournisseur) + { + print '<tr><td>'; + print $langs->trans('SupplierCode').'</td><td colspan="3">'; + print $soc->code_fournisseur; + if ($soc->check_codefournisseur() <> 0) print ' <font class="error">('.$langs->trans("WrongSupplierCode").')</font>'; + print '</td></tr>'; + } + + if (! empty($conf->barcode->enabled)) + { + print '<tr><td>'.$langs->trans('Gencod').'</td><td colspan="3">'.$soc->barcode.'</td></tr>'; + } + + print "<tr><td valign=\"top\">".$langs->trans('Address')."</td><td colspan=\"3\">"; + dol_print_address($soc->address, 'gmap', 'thirdparty', $soc->id); + print "</td></tr>"; + + // Zip / Town + print '<tr><td width="25%">'.$langs->trans('Zip').'</td><td width="25%">'.$soc->zip."</td>"; + print '<td width="25%">'.$langs->trans('Town').'</td><td width="25%">'.$soc->town."</td></tr>"; + + // Country + if ($soc->country) { + print '<tr><td>'.$langs->trans('Country').'</td><td colspan="3">'; + $img=picto_from_langcode($soc->country_code); + print ($img?$img.' ':''); + print $soc->country; + print '</td></tr>'; + } + + // EMail + print '<tr><td>'.$langs->trans('EMail').'</td><td colspan="3">'; + print dol_print_email($soc->email,0,$soc->id,'AC_EMAIL'); + print '</td></tr>'; + + // Web + print '<tr><td>'.$langs->trans('Web').'</td><td colspan="3">'; + print dol_print_url($soc->url); + print '</td></tr>'; + + // Phone / Fax + print '<tr><td>'.$langs->trans('Phone').'</td><td>'.dol_print_phone($soc->tel,$soc->country_code,0,$soc->id,'AC_TEL').'</td>'; + print '<td>'.$langs->trans('Fax').'</td><td>'.dol_print_phone($soc->fax,$soc->country_code,0,$soc->id,'AC_FAX').'</td></tr>'; + + + if($mysoc->localtax1_assuj=="1" && $mysoc->localtax2_assuj=="1") + { + print '<tr><td class="nowrap">'.$langs->trans('LocalTax1IsUsedES').'</td><td colspan="3">'; + print yn($soc->localtax1_assuj); + print '</td></tr>'; + print '<tr><td class="nowrap">'.$langs->trans('LocalTax2IsUsedES').'</td><td colspan="3">'; + print yn($soc->localtax2_assuj); + print '</td></tr>'; + } + elseif($mysoc->localtax1_assuj=="1") + { + print '<tr><td>'.$langs->trans("LocalTax1IsUsedES").'</td><td colspan="3">'; + print yn($soc->localtax1_assuj); + print '</td></tr>'; + } + elseif($mysoc->localtax2_assuj=="1") + { + print '<tr><td>'.$langs->trans("LocalTax2IsUsedES").'</td><td colspan="3">'; + print yn($soc->localtax2_assuj); + print '</td></tr>'; + } + + + print '</table>'; + + print '</div>'; + + // Localtaxes + + print '<table id="tablelines" class="noborder" width="100%">'; + + print '<tr class="liste_titre nodrag nodrop">'; + + // Description + print '<td>'.$langs->trans('Description').'</td>'; + + // VAT + print '<td align="right" width="80">'.$langs->trans('VAT').' (%)</td>'; + + // Localtax 1 + if ($mysoc->localtax1_assuj=="1" && $soc->localtax1_assuj) + print '<td align="right" width="80">'.$langs->trans('Localtax1').' (%)</td>'; + + if ($mysoc->localtax2_assuj=="1" && $soc->localtax2_assuj) + print '<td align="right" width="80">'.$langs->trans('Localtax2').' (%)</td>'; + + //print '<td width="10"></td>'; + + print '<td width="10" class="nowrap"></td>'; // No width to allow autodim + + print "</tr>\n"; + + + $sql = "SELECT DISTINCT t.rowid, t.note, t.taux, t.localtax1, t.localtax2, t.recuperableonly"; + $sql.= " FROM ".MAIN_DB_PREFIX."c_tva as t, ".MAIN_DB_PREFIX."c_pays as p"; + $sql.= " WHERE t.fk_pays = p.rowid"; + $sql.= " AND t.active = 1"; + $sql.= " AND p.code IN ('".$mysoc->country_code."')"; + $sql.= " ORDER BY t.taux ASC, t.recuperableonly ASC"; + + $resql=$db->query($sql); + if ($resql) + { + $num = $db->num_rows($resql); + if ($num) + { + $var=True; + for ($i = 0; $i < $num; $i++) + { + $var=!$var; + + + $obj = $db->fetch_object($resql); + + if ($action == 'edit' && $obj->rowid==$vatid) + { + print '<form action="'.$_SERVER["PHP_SELF"].'?socid='.$soc->id.'" method="post">'; + print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">'; + print '<input type="hidden" name="action" value="updatetva">'; + print '<input type="hidden" name="vatid" value="'.$vatid.'">'; + + print '<tr '.$bc[$var].'>'; + + print '<td>'.$obj->note.'</td>'; + print '<td align="right">'.$obj->taux.'</td>'; + + if ($mysoc->localtax1_assuj=="1" && $soc->localtax1_assuj) + print '<td align="right"><input size="4" type="text" class="flat" name="localtax1" value="'.$obj->localtax1.'"></td>'; + if ($mysoc->localtax2_assuj=="1" && $soc->localtax2_assuj) + print '<td align="right"><input size="4" type="text" class="flat" name="localtax2" value="'.$obj->localtax2.'"></td>'; + + print '<td align="right"><input type="submit" class="button" name="save" value="'.$langs->trans('Save').'">'; + print '<br><input type="submit" class="button" name="cancel" value="'.$langs->trans('Cancel').'"></td>'; + print '</tr>'; + print '</form>'; + } + else + { + print '<tr '.$bc[$var].'>'; + + print '<td>'.$obj->note.'</td>'; + print '<td align="right">'.$obj->taux.'</td>'; + if ($mysoc->localtax1_assuj=="1" && $soc->localtax1_assuj) + print '<td align="right">'.$obj->localtax1.'</td>'; + if ($mysoc->localtax2_assuj=="1" && $soc->localtax2_assuj) + print '<td align="right">'.$obj->localtax2.'</td>'; + print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=edit&socid='.$soc->id.'&vatid='.$obj->rowid.'">'.img_edit().'</a></td>'; + print "</tr>\n"; + } + + + } + } + } +} + + +llxFooter(); + +$db->close(); +?> -- GitLab