* Copyright (C) 2005-2013 Regis Houssin * Copyright (C) 2016-2018 Frédéric France * Copyright (C) 2017 Alexandre Spangaro * * 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 . */ /** * \file htdocs/compta/sociales/card.php * \ingroup tax * \brief Social contribution card page */ require '../../main.inc.php'; require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php'; require_once DOL_DOCUMENT_ROOT.'/compta/sociales/class/chargesociales.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/html.formsocialcontrib.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/tax.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php'; if (! empty($conf->projet->enabled)) { include_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php'; include_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php'; } if (! empty($conf->accounting->enabled)) { include_once DOL_DOCUMENT_ROOT . '/accountancy/class/accountingjournal.class.php'; } // Load translation files required by the page $langs->loadLangs(array('compta', 'bills', 'banks')); $id=GETPOST('id','int'); $action=GETPOST('action','aZ09'); $confirm=GETPOST('confirm'); $projectid = (GETPOST('projectid') ? GETPOST('projectid', 'int') : 0); // Security check $socid = GETPOST('socid','int'); if ($user->societe_id) $socid=$user->societe_id; $result = restrictedArea($user, 'tax', $id, 'chargesociales','charges'); $object = new ChargeSociales($db); /* *************************************************************************** */ /* */ /* Actions */ /* */ /* *************************************************************************** */ // Classify paid if ($action == 'confirm_paid' && $user->rights->tax->charges->creer && $confirm == 'yes') { $object->fetch($id); $result = $object->set_paid($user); } if ($action == 'reopen' && $user->rights->tax->charges->creer) { $result = $object->fetch($id); if ($object->paye) { $result = $object->set_unpaid($user); if ($result > 0) { header('Location: ' . $_SERVER["PHP_SELF"] . '?id=' . $id); exit(); } else { setEventMessages($object->error, $object->errors, 'errors'); } } } // Link to a project if ($action == 'classin' && $user->rights->tax->charges->creer) { $object->fetch($id); $object->setProject(GETPOST('projectid')); } if ($action == 'setlib' && $user->rights->tax->charges->creer) { $object->fetch($id); $result = $object->setValueFrom('libelle', GETPOST('lib'), '', '', 'text', '', $user, 'TAX_MODIFY'); if ($result < 0) setEventMessages($object->error, $object->errors, 'errors'); } // payment mode if ($action == 'setmode' && $user->rights->tax->charges->creer) { $object->fetch($id); $result = $object->setPaymentMethods(GETPOST('mode_reglement_id', 'int')); if ($result < 0) setEventMessages($object->error, $object->errors, 'errors'); } // bank account if ($action == 'setbankaccount' && $user->rights->tax->charges->creer) { $object->fetch($id); $result=$object->setBankAccount(GETPOST('fk_account', 'int')); if ($result < 0) { setEventMessages($object->error, $object->errors, 'errors'); } } // Delete social contribution if ($action == 'confirm_delete' && $confirm == 'yes') { $object->fetch($id); $result=$object->delete($user); if ($result > 0) { header("Location: index.php"); exit; } else { setEventMessages($object->error, $object->errors, 'errors'); } } // Add social contribution if ($action == 'add' && $user->rights->tax->charges->creer) { $dateech=dol_mktime(GETPOST('echhour'),GETPOST('echmin'),GETPOST('echsec'),GETPOST('echmonth'),GETPOST('echday'),GETPOST('echyear')); $dateperiod=dol_mktime(GETPOST('periodhour'),GETPOST('periodmin'),GETPOST('periodsec'),GETPOST('periodmonth'),GETPOST('periodday'),GETPOST('periodyear')); $amount=price2num(GETPOST('amount')); $actioncode=GETPOST('actioncode'); if (! $dateech) { setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("DateDue")), null, 'errors'); $action = 'create'; } elseif (! $dateperiod) { setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Period")), null, 'errors'); $action = 'create'; } elseif (! $actioncode > 0) { setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Type")), null, 'errors'); $action = 'create'; } elseif (empty($amount)) { setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Amount")), null, 'errors'); $action = 'create'; } elseif (! is_numeric($amount)) { setEventMessages($langs->trans("ErrorFieldMustBeANumeric",$langs->transnoentities("Amount")), null, 'errors'); $action = 'create'; } else { $object->type = $actioncode; $object->lib = GETPOST('label'); $object->date_ech = $dateech; $object->periode = $dateperiod; $object->amount = $amount; $object->mode_reglement_id = GETPOST('mode_reglement_id'); $object->fk_account = GETPOST('fk_account', 'int'); $object->fk_project = GETPOST('fk_project'); $id=$object->create($user); if ($id <= 0) { setEventMessages($object->error, $object->errors, 'errors'); $action='create'; } } } if ($action == 'update' && ! $_POST["cancel"] && $user->rights->tax->charges->creer) { $dateech=dol_mktime(GETPOST('echhour'),GETPOST('echmin'),GETPOST('echsec'),GETPOST('echmonth'),GETPOST('echday'),GETPOST('echyear')); $dateperiod=dol_mktime(GETPOST('periodhour'),GETPOST('periodmin'),GETPOST('periodsec'),GETPOST('periodmonth'),GETPOST('periodday'),GETPOST('periodyear')); $amount=price2num(GETPOST('amount')); if (! $dateech) { setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("DateDue")), null, 'errors'); $action = 'edit'; } elseif (! $dateperiod) { setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Period")), null, 'errors'); $action = 'edit'; } elseif (empty($amount)) { setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Amount")), null, 'errors'); $action = 'edit'; } elseif (! is_numeric($amount)) { setEventMessages($langs->trans("ErrorFieldMustBeANumeric",$langs->transnoentities("Amount")), null, 'errors'); $action = 'create'; } else { $result=$object->fetch($id); $object->date_ech = $dateech; $object->periode = $dateperiod; $object->amount = price2num($amount); $result=$object->update($user); if ($result <= 0) { setEventMessages($object->error, $object->errors, 'errors'); } } } // Action clone object if ($action == 'confirm_clone' && $confirm != 'yes') { $action=''; } if ($action == 'confirm_clone' && $confirm == 'yes' && ($user->rights->tax->charges->creer)) { $db->begin(); $originalId = $id; $object->fetch($id); if ($object->id > 0) { $object->paye = 0; $object->id = $object->ref = null; $object->lib = $langs->trans("CopyOf").' '.$object->lib; if (GETPOST('clone_for_next_month') != '') { $object->date_ech = dol_time_plus_duree($object->date_ech, 1, 'm'); $object->periode = dol_time_plus_duree($object->periode, 1, 'm'); } if ($object->check()) { $id = $object->create($user); if ($id > 0) { $db->commit(); $db->close(); header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id); exit; } else { $id=$originalId; $db->rollback(); setEventMessages($object->error,$object->errors, 'errors'); } } } else { $db->rollback(); dol_print_error($db,$object->error); } } /* * View */ $form = new Form($db); $formsocialcontrib = new FormSocialContrib($db); $bankaccountstatic = new Account($db); if (! empty($conf->projet->enabled)) { $formproject = new FormProjets($db); } $title = $langs->trans("SocialContribution") . ' - ' . $langs->trans("Card"); $help_url='EN:Module_Taxes_and_social_contributions|FR:Module Taxes et dividendes|ES:Módulo Impuestos y cargas sociales (IVA, impuestos)'; llxHeader("",$title,$help_url); // Mode creation if ($action == 'create') { print load_fiche_titre($langs->trans("NewSocialContribution")); print '
'; print ''; print ''; dol_fiche_head(); print ''; // Label print ""; print ''; print ''; print ''; print ''; // Type print ''; print ''; print ''; // Date end period print ''; print ''; print ''; print ''; // Date due print ''; print ''; print ''; print "\n"; // Amount print ''; print ''; print ''; print ''; // Project if (! empty($conf->projet->enabled)) { $formproject=new FormProjets($db); // Associated project $langs->load("projects"); print ''; } // Payment Mode print ''; // Bank Account if (! empty($conf->banque->enabled)) { print ''; } print '
'; print $langs->trans("Label"); print '
'; print $langs->trans("Type"); print ''; $formsocialcontrib->select_type_socialcontrib(GETPOST("actioncode",'alpha')?GETPOST("actioncode",'alpha'):'','actioncode',1); print '
'; print $form->textwithpicto($langs->trans("PeriodEndDate"), $langs->trans("LastDayTaxIsRelatedTo")); print ''; print $form->selectDate(! empty($dateperiod)?$dateperiod:'-1', 'period', 0, 0, 0, 'charge', 1); print '
'; print $langs->trans("DateDue"); print ''; print $form->selectDate(! empty($dateech)?$dateech:'-1', 'ech', 0, 0, 0, 'charge', 1); print '
'; print $langs->trans("Amount"); print '
'.$langs->trans("Project").''; $numproject=$formproject->select_projects(-1, $projectid,'fk_project',0,0,1,1); print '
' . $langs->trans('PaymentMode') . ''; $form->select_types_paiements($mode_reglement_id, 'mode_reglement_id'); print '
' . $langs->trans('BankAccount') . ''; $form->select_comptes($fk_account, 'fk_account', 0, '', 1); print '
'; dol_fiche_end(); print '
'; print ''; print '     '; print ''; print '
'; print '
'; } /* *************************************************************************** */ /* */ /* Card Mode */ /* */ /* *************************************************************************** */ if ($id > 0) { $object = new ChargeSociales($db); $result=$object->fetch($id); if ($result > 0) { $head=tax_prepare_head($object); $totalpaye = $object->getSommePaiement(); // Clone confirmation if ($action === 'clone') { $formclone=array( array('type' => 'checkbox', 'name' => 'clone_for_next_month','label' => $langs->trans("CloneTaxForNextMonth"), 'value' => 1), ); print $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id,$langs->trans('CloneTax'),$langs->trans('ConfirmCloneTax',$object->ref),'confirm_clone',$formclone,'yes'); } // Confirmation de la suppression de la charge if ($action == 'paid') { $text=$langs->trans('ConfirmPaySocialContribution'); print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id,$langs->trans('PaySocialContribution'),$text,"confirm_paid",'','',2); } if ($action == 'delete') { $text=$langs->trans('ConfirmDeleteSocialContribution'); print $form->formconfirm($_SERVER['PHP_SELF'].'?id='.$object->id,$langs->trans('DeleteSocialContribution'),$text,'confirm_delete','','',2); } if ($action == 'edit') { print "
id&action=update\" method=\"post\">"; print ''; } dol_fiche_head($head, 'card', $langs->trans("SocialContribution"), -1, 'bill'); $morehtmlref='
'; // Ref customer $morehtmlref.=$form->editfieldkey("Label", 'lib', $object->lib, $object, $user->rights->tax->charges->creer, 'string', '', 0, 1); $morehtmlref.=$form->editfieldval("Label", 'lib', $object->lib, $object, $user->rights->tax->charges->creer, 'string', '', null, null, '', 1); // Project if (! empty($conf->projet->enabled)) { $langs->load("projects"); $morehtmlref.='
'.$langs->trans('Project') . ' '; if ($user->rights->tax->charges->creer) { if ($action != 'classify') $morehtmlref.='' . img_edit($langs->transnoentitiesnoconv('SetProject')) . ' : '; if ($action == 'classify') { //$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1); $morehtmlref.=''; $morehtmlref.=''; $morehtmlref.=''; $morehtmlref.=$formproject->select_projects(0, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1); $morehtmlref.=''; $morehtmlref.=''; } else { $morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1); } } else { if (! empty($object->fk_project)) { $proj = new Project($db); $proj->fetch($object->fk_project); $morehtmlref.=''; $morehtmlref.=$proj->ref; $morehtmlref.=''; } else { $morehtmlref.=''; } } } $morehtmlref.='
'; $linkback = '' . $langs->trans("BackToList") . ''; $object->totalpaye = $totalpaye; // To give a chance to dol_banner_tab to use already paid amount to show correct status dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'ref', $morehtmlref, '', 0, '', $morehtmlright); print '
'; print '
'; print '
'; print ''; // Type print '"; print ""; // Period end date print ""; print ""; // Due date if ($action == 'edit') { print '"; } else { print ""; } // Amount if ($action == 'edit') { print '"; } else { print ''; } // Mode of payment print ''; // Bank Account if (! empty($conf->banque->enabled)) { print ''; print ''; } print '
'.$langs->trans("Type")."".$object->type_libelle."
".$form->textwithpicto($langs->trans("PeriodEndDate"), $langs->trans("LastDayTaxIsRelatedTo")).""; if ($action == 'edit') { print $form->selectDate($object->periode, 'period', 0, 0, 0, 'charge', 1); } else { print dol_print_date($object->periode,"day"); } print "
'.$langs->trans("DateDue").""; print $form->selectDate($object->date_ech, 'ech', 0, 0, 0, 'charge', 1); print "
".$langs->trans("DateDue")."".dol_print_date($object->date_ech,'day')."
'.$langs->trans("AmountTTC").""; print ''; print "
'.$langs->trans("AmountTTC").''.price($object->amount,0,$outputlangs,1,-1,-1,$conf->currency).'
'; print ''; if ($action != 'editmode') print ''; print '
'; print $langs->trans('PaymentMode'); print 'id . '">' . img_edit($langs->trans('SetMode'), 1) . '
'; print '
'; if ($action == 'editmode') { $form->form_modes_reglement($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->mode_reglement_id, 'mode_reglement_id'); } else { $form->form_modes_reglement($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->mode_reglement_id, 'none'); } print '
'; print ''; print '
'; print $langs->trans('BankAccount'); print ''; if ($action != 'editbankaccount' && $user->rights->tax->charges->creer) print 'id.'">'.img_edit($langs->trans('SetBankAccount'),1).'
'; print '
'; if ($action == 'editbankaccount') { $form->formSelectAccount($_SERVER['PHP_SELF'].'?id='.$object->id, $object->fk_account, 'fk_account', 1); } else { $form->formSelectAccount($_SERVER['PHP_SELF'].'?id='.$object->id, $object->fk_account, 'none'); } print '
'; print '
'; print '
'; print '
'; $nbcols = 3; if (! empty($conf->banque->enabled)) { $nbcols ++; } /* * Payments */ $sql = "SELECT p.rowid, p.num_paiement, datep as dp, p.amount,"; $sql.= " c.code as type_code,c.libelle as paiement_type,"; $sql.= ' ba.rowid as baid, ba.ref as baref, ba.label, ba.number as banumber, ba.account_number, ba.fk_accountancy_journal'; $sql.= " FROM ".MAIN_DB_PREFIX."paiementcharge as p"; $sql.= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'bank as b ON p.fk_bank = b.rowid'; $sql.= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'bank_account as ba ON b.fk_account = ba.rowid'; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as c ON p.fk_typepaiement = c.id"; $sql.= ", ".MAIN_DB_PREFIX."chargesociales as cs"; $sql.= " WHERE p.fk_charge = ".$id; $sql.= " AND p.fk_charge = cs.rowid"; $sql.= " AND cs.entity IN (".getEntity('tax').")"; $sql.= " ORDER BY dp DESC"; //print $sql; $resql = $db->query($sql); if ($resql) { $totalpaye = 0; $num = $db->num_rows($resql); $i = 0; $total = 0; print ''; print ''; print ''; print ''; print ''; if (! empty($conf->banque->enabled)) { print ''; } print ''; print ''; if ($num > 0) { while ($i < $num) { $objp = $db->fetch_object($resql); print ''; print '\n"; $labeltype=$langs->trans("PaymentType".$objp->type_code)!=("PaymentType".$objp->type_code)?$langs->trans("PaymentType".$objp->type_code):$objp->paiement_type; print "\n"; if (! empty($conf->banque->enabled)) { $bankaccountstatic->id = $objp->baid; $bankaccountstatic->ref = $objp->baref; $bankaccountstatic->label = $objp->baref; $bankaccountstatic->number = $objp->banumber; if (! empty($conf->accounting->enabled)) { $bankaccountstatic->account_number = $objp->account_number; $accountingjournal = new AccountingJournal($db); $accountingjournal->fetch($objp->fk_accountancy_journal); $bankaccountstatic->accountancy_journal = $accountingjournal->getNomUrl(0,1,1,'',1); } print ''; } print '\n"; print ""; $totalpaye += $objp->amount; $i++; } } else { print ''; print ''; print ''; } print '\n"; print '\n"; $resteapayer = $object->amount - $totalpaye; $cssforamountpaymentcomplete = 'amountpaymentcomplete'; print '"; print '\n"; print "
'.$langs->trans("RefPayment").''.$langs->trans("Date").''.$langs->trans("Type").'' . $langs->trans('BankAccount') . ''.$langs->trans("Amount").'
'; print ''.img_object($langs->trans("Payment"),"payment").' '.$objp->rowid.''.dol_print_date($db->jdate($objp->dp),'day')."".$labeltype.' '.$objp->num_paiement."'; if ($bankaccountstatic->id) print $bankaccountstatic->getNomUrl(1, 'transactions'); print ''.price($objp->amount)."
'.$langs->trans("None").'
'.$langs->trans("AlreadyPaid")." :".price($totalpaye)."
'.$langs->trans("AmountExpected")." :".price($object->amount)."
'.$langs->trans("RemainderToPay")." :'.price($resteapayer)."
"; $db->free($resql); } else { dol_print_error($db); } print '
'; print '
'; print '
'; print '
'; dol_fiche_end(); if ($action == 'edit') { print '
'; print ''; print '   '; print ''; print '
'; } if ($action == 'edit') print "\n"; /* * Actions buttons */ if ($action != 'edit') { print "
\n"; // Reopen if ($object->paye && $user->rights->tax->charges->creer) { print "id&action=reopen\">".$langs->trans("ReOpen").""; } // Edit if ($object->paye == 0 && $user->rights->tax->charges->creer) { print "id&action=edit\">".$langs->trans("Modify").""; } // Emit payment if ($object->paye == 0 && ((price2num($object->amount) < 0 && price2num($resteapayer, 'MT') < 0) || (price2num($object->amount) > 0 && price2num($resteapayer, 'MT') > 0)) && $user->rights->tax->charges->creer) { print "id&action=create\">".$langs->trans("DoPayment").""; } // Classify 'paid' if ($object->paye == 0 && round($resteapayer) <=0 && $user->rights->tax->charges->creer) { print "id&action=paid\">".$langs->trans("ClassifyPaid").""; } // Clone if ($user->rights->tax->charges->creer) { print "id&action=clone\">".$langs->trans("ToClone").""; } // Delete if ($user->rights->tax->charges->supprimer) { print "id&action=delete\">".$langs->trans("Delete").""; } print "
"; } } else { /* Social contribution not found */ dol_print_error('',$object->error); } } // End of page llxFooter(); $db->close();