New Module : Manage Financial Loan
This commit is contained in:
parent
cf7973d0fa
commit
08b9e05425
119
htdocs/admin/loan.php
Normal file
119
htdocs/admin/loan.php
Normal file
@ -0,0 +1,119 @@
|
||||
<?php
|
||||
/* Copyright (C) 2014 Alexandre Spangaro <alexandre.spangaro@gmail.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/>.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file htdocs/admin/loan.php
|
||||
* \ingroup loan
|
||||
* \brief Setup page to configure loan module
|
||||
*/
|
||||
|
||||
require '../main.inc.php';
|
||||
|
||||
// Class
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
|
||||
|
||||
$langs->load("admin");
|
||||
$langs->load("loan");
|
||||
|
||||
// Security check
|
||||
if (!$user->admin)
|
||||
accessforbidden();
|
||||
|
||||
$action = GETPOST('action', 'alpha');
|
||||
|
||||
// Other parameters LOAN_*
|
||||
$list = array (
|
||||
'LOAN_ACCOUNTING_ACCOUNT_CAPITAL',
|
||||
'LOAN_ACCOUNTING_ACCOUNT_INTEREST',
|
||||
'LOAN_ACCOUNTING_ACCOUNT_INSURANCE'
|
||||
);
|
||||
|
||||
/*
|
||||
* Actions
|
||||
*/
|
||||
|
||||
if ($action == 'update')
|
||||
{
|
||||
$error = 0;
|
||||
|
||||
foreach ($list as $constname) {
|
||||
$constvalue = GETPOST($constname, 'alpha');
|
||||
|
||||
if (!dolibarr_set_const($db, $constname, $constvalue, 'chaine', 0, '', $conf->entity)) {
|
||||
$error++;
|
||||
}
|
||||
}
|
||||
|
||||
if (! $error)
|
||||
{
|
||||
setEventMessage($langs->trans("SetupSaved"));
|
||||
}
|
||||
else
|
||||
{
|
||||
setEventMessage($langs->trans("Error"),'errors');
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* View
|
||||
*/
|
||||
|
||||
llxHeader();
|
||||
|
||||
$form = new Form($db);
|
||||
|
||||
$linkback='<a href="'.DOL_URL_ROOT.'/admin/modules.php">'.$langs->trans("BackToModuleList").'</a>';
|
||||
print_fiche_titre($langs->trans('ConfigLoan'),$linkback,'setup');
|
||||
|
||||
print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">';
|
||||
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
|
||||
print '<input type="hidden" name="action" value="update">';
|
||||
|
||||
/*
|
||||
* Params
|
||||
*/
|
||||
print '<table class="noborder" width="100%">';
|
||||
print '<tr class="liste_titre">';
|
||||
print '<td colspan="3">' . $langs->trans('Options') . '</td>';
|
||||
print "</tr>\n";
|
||||
|
||||
foreach ($list as $key)
|
||||
{
|
||||
$var=!$var;
|
||||
|
||||
print '<tr '.$bc[$var].' class="value">';
|
||||
|
||||
// Param
|
||||
$label = $langs->trans($key);
|
||||
print '<td><label for="'.$key.'">'.$label.'</label></td>';
|
||||
|
||||
// Value
|
||||
print '<td>';
|
||||
print '<input type="text" size="20" id="'.$key.'" name="'.$key.'" value="'.$conf->global->$key.'">';
|
||||
print '</td></tr>';
|
||||
}
|
||||
|
||||
print '</tr>';
|
||||
|
||||
print '</form>';
|
||||
print "</table>\n";
|
||||
|
||||
print '<br /><div style="text-align:center"><input type="submit" class="button" value="'.$langs->trans('Modify').'" name="button"></div>';
|
||||
|
||||
llxFooter();
|
||||
$db->close();
|
||||
467
htdocs/compta/loan/card.php
Normal file
467
htdocs/compta/loan/card.php
Normal file
@ -0,0 +1,467 @@
|
||||
<?php
|
||||
/* Copyright (C) 2014 Alexandre Spangaro <alexandre.spangaro@gmail.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/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file htdocs/compta/loan/card.php
|
||||
* \ingroup loan
|
||||
* \brief Loan card
|
||||
*/
|
||||
|
||||
require '../../main.inc.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/compta/loan/class/loan.class.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/lib/loan.lib.php';
|
||||
|
||||
$langs->load("compta");
|
||||
$langs->load("bills");
|
||||
$langs->load("loan");
|
||||
|
||||
$id=GETPOST('id','int');
|
||||
$action=GETPOST("action");
|
||||
$confirm=GETPOST('confirm');
|
||||
|
||||
// Security check
|
||||
$socid = GETPOST('socid','int');
|
||||
if ($user->societe_id) $socid=$user->societe_id;
|
||||
$result = restrictedArea($user, 'loan', $id, '','');
|
||||
|
||||
/*
|
||||
* Actions
|
||||
*/
|
||||
|
||||
// Classify paid
|
||||
if ($action == 'confirm_paid' && $confirm == 'yes')
|
||||
{
|
||||
$loan = new Loan($db);
|
||||
$loan->fetch($id);
|
||||
$result = $loan->set_paid($user);
|
||||
}
|
||||
|
||||
// Delete loan
|
||||
if ($action == 'confirm_delete' && $confirm == 'yes')
|
||||
{
|
||||
$loan = new Loan($db);
|
||||
$loan->fetch($id);
|
||||
$result=$loan->delete($user);
|
||||
if ($result > 0)
|
||||
{
|
||||
header("Location: index.php");
|
||||
exit;
|
||||
}
|
||||
else
|
||||
{
|
||||
setEventMessage($loan->error, 'errors');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Add loan
|
||||
if ($action == 'add' && $user->rights->loan->write)
|
||||
{
|
||||
$dateech=@dol_mktime($_POST["echhour"],$_POST["echmin"],$_POST["echsec"],$_POST["echmonth"],$_POST["echday"],$_POST["echyear"]);
|
||||
$dateperiod=@dol_mktime($_POST["periodhour"],$_POST["periodmin"],$_POST["periodsec"],$_POST["periodmonth"],$_POST["periodday"],$_POST["periodyear"]);
|
||||
if (! $dateech)
|
||||
{
|
||||
setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentities("DateDue")), 'errors');
|
||||
$action = 'create';
|
||||
}
|
||||
elseif (! $dateperiod)
|
||||
{
|
||||
setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentities("Period")), 'errors');
|
||||
$action = 'create';
|
||||
}
|
||||
elseif (! $_POST["capital"])
|
||||
{
|
||||
setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentities("Capital")), 'errors');
|
||||
$action = 'create';
|
||||
}
|
||||
else
|
||||
{
|
||||
$loan = new Loan($db);
|
||||
|
||||
$loan->label = $_POST["label"];
|
||||
$loan->date_ech = $dateech;
|
||||
$loan->periode = $dateperiod;
|
||||
$loan->capital = $_POST["capital"];
|
||||
|
||||
$id=$loan->create($user);
|
||||
if ($id <= 0)
|
||||
{
|
||||
setEventMessage($loan->error, 'errors');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if ($action == 'update' && ! $_POST["cancel"] && $user->rights->loan->write)
|
||||
{
|
||||
$dateech=dol_mktime($_POST["echhour"],$_POST["echmin"],$_POST["echsec"],$_POST["echmonth"],$_POST["echday"],$_POST["echyear"]);
|
||||
$dateperiod=dol_mktime($_POST["periodhour"],$_POST["periodmin"],$_POST["periodsec"],$_POST["periodmonth"],$_POST["periodday"],$_POST["periodyear"]);
|
||||
if (! $dateech)
|
||||
{
|
||||
setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentities("DateDue")), 'errors');
|
||||
$action = 'edit';
|
||||
}
|
||||
elseif (! $dateperiod)
|
||||
{
|
||||
setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentities("Period")), 'errors');
|
||||
$action = 'edit';
|
||||
}
|
||||
else
|
||||
{
|
||||
$loan = new Loan($db);
|
||||
$result=$loan->fetch($_GET["id"]);
|
||||
|
||||
$loan->lib=$_POST["label"];
|
||||
$loan->date_ech=$dateech;
|
||||
$loan->periode=$dateperiod;
|
||||
|
||||
$result=$loan->update($user);
|
||||
if ($result <= 0)
|
||||
{
|
||||
setEventMessage($loan->error, 'errors');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* View
|
||||
*/
|
||||
|
||||
$form = new Form($db);
|
||||
|
||||
$help_url='EN:Module_Loan|FR:Module Emprunt';
|
||||
llxHeader("",$langs->trans("Loan"),$help_url);
|
||||
|
||||
|
||||
// Create mode
|
||||
if ($action == 'create')
|
||||
{
|
||||
//WYSIWYG Editor
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
|
||||
|
||||
print_fiche_titre($langs->trans("NewLoan"));
|
||||
|
||||
$datec = dol_mktime(12, 0, 0, GETPOST('remonth','int'), GETPOST('reday','int'), GETPOST('reyear','int'));
|
||||
|
||||
print '<form name="add" action="' . $_SERVER["PHP_SELF"] . '" method="POST">' . "\n";
|
||||
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
|
||||
print '<input type="hidden" name="action" value="add">';
|
||||
|
||||
print '<table class="border" width="100%">';
|
||||
|
||||
// Label
|
||||
print '<tr><td width="25%" class="fieldrequired">'.$langs->trans("Label").'</td><td colspan="3"><input name="label" size="40" maxlength="255" value="'.dol_escape_htmltag(GETPOST('label')).'"></td></tr>';
|
||||
|
||||
// Bank account
|
||||
if (! empty($conf->banque->enabled))
|
||||
{
|
||||
print '<tr><td class="fieldrequired">'.$langs->trans("Account").'</td><td>';
|
||||
$form->select_comptes($_POST["accountid"],"accountid",0,"courant=1",1); // Show list of bank account with courant
|
||||
print '</td></tr>';
|
||||
}
|
||||
else
|
||||
{
|
||||
print '<tr><td>'.$langs->trans("Account").'</td><td>';
|
||||
print $langs->trans("NoBankAccountDefined");
|
||||
print '</td></tr>';
|
||||
}
|
||||
|
||||
// Capital
|
||||
print '<tr><td class="fieldrequired">'.$langs->trans("Capital").'</td><td><input name="capital" size="10" value="' . GETPOST("capital") . '"></td></tr>';
|
||||
|
||||
// Date Start
|
||||
print "<tr>";
|
||||
print '<td class="fieldrequired">'.$langs->trans("DateStart").'</td><td>';
|
||||
print $form->select_date($datestart?$datestart:-1,'','','','','add',1,1);
|
||||
print '</td></tr>';
|
||||
|
||||
// Date End
|
||||
print "<tr>";
|
||||
print '<td class="fieldrequired">'.$langs->trans("DateEnd").'</td><td>';
|
||||
print $form->select_date($dateend?$dateend:-1,'','','','','add',1,1);
|
||||
print '</td></tr>';
|
||||
|
||||
// Number of terms
|
||||
print '<tr><td class="fieldrequired">'.$langs->trans("Nbterms").'</td><td><input name="nbterm" size="4" value="' . GETPOST('nbterm') . '"></td></tr>';
|
||||
|
||||
// Rate
|
||||
print '<tr><td class="fieldrequired">'.$langs->trans("Rate").'</td><td><input name="rate" size="10" value="' . GETPOST("rate") . '"></td></tr>';
|
||||
|
||||
// Note
|
||||
print '<tr>';
|
||||
print '<td class="border" valign="top">'.$langs->trans('Note').'</td>';
|
||||
print '<td valign="top" colspan="2">';
|
||||
|
||||
$doleditor = new DolEditor('note', GETPOST('note', 'alpha'), '', 200, 'dolibarr_notes', 'In', false, true, true, ROWS_8, 100);
|
||||
print $doleditor->Create(1);
|
||||
|
||||
print '</td></tr>';
|
||||
print '</table>';
|
||||
|
||||
print '<br>';
|
||||
|
||||
// Accountancy
|
||||
print '<table class="border" width="100%">';
|
||||
|
||||
if ($conf->accounting->enabled)
|
||||
{
|
||||
print '<tr><td width="25%" class="fieldrequired">'.$langs->trans("LoanAccountancyCapitalCode").'</td>';
|
||||
print '<td><input name="accountancy_account_capital" size="16" value="'.$object->accountancy_account_capital.'">';
|
||||
print '</td></tr>';
|
||||
|
||||
print '<tr><td class="fieldrequired">'.$langs->trans("LoanAccountancyInsuranceCode").'</td>';
|
||||
print '<td><input name="accountancy_account_insurance" size="16" value="'.$object->accountancy_account_insurance.'">';
|
||||
print '</td></tr>';
|
||||
|
||||
print '<tr><td class="fieldrequired">'.$langs->trans("LoanAccountancyInterestCode").'</td>';
|
||||
print '<td><input name="accountancy_account_interest" size="16" value="'.$object->accountancy_account_interest.'">';
|
||||
print '</td></tr>';
|
||||
}
|
||||
else
|
||||
{
|
||||
print '<tr><td width="25%">'.$langs->trans("LoanAccountancyCapitalCode").'</td>';
|
||||
print '<td><input name="accountancy_account_capital" size="16" value="'.$object->accountancy_account_capital.'">';
|
||||
print '</td></tr>';
|
||||
|
||||
print '<tr><td>'.$langs->trans("LoanAccountancyInsuranceCode").'</td>';
|
||||
print '<td><input name="accountancy_account_insurance" size="16" value="'.$object->accountancy_account_insurance.'">';
|
||||
print '</td></tr>';
|
||||
|
||||
print '<tr><td>'.$langs->trans("LoanAccountancyInterestCode").'</td>';
|
||||
print '<td><input name="accountancy_account_interest" size="16" value="'.$object->accountancy_account_interest.'">';
|
||||
print '</td></tr>';
|
||||
}
|
||||
|
||||
print '</table>';
|
||||
|
||||
print '<br><center><input class="button" type="submit" value="'.$langs->trans("Save").'"> ';
|
||||
print '<input class="button" type="submit" name="cancel" value="'.$langs->trans("Cancel").'"></center';
|
||||
|
||||
print '</form>';
|
||||
}
|
||||
|
||||
// View
|
||||
if ($id > 0)
|
||||
{
|
||||
$object = new Loan($db);
|
||||
$result=$object->fetch($id);
|
||||
|
||||
if ($result > 0)
|
||||
{
|
||||
$head=loan_prepare_head($object);
|
||||
|
||||
dol_fiche_head($head, 'card', $langs->trans("Loan"),0,'bill');
|
||||
|
||||
// Confirm for loan
|
||||
if ($action == 'paid')
|
||||
{
|
||||
$text=$langs->trans('ConfirmPayLoan');
|
||||
print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id,$langs->trans('PayLoan'),$text,"confirm_paid",'','',2);
|
||||
}
|
||||
|
||||
if ($action == 'delete')
|
||||
{
|
||||
$text=$langs->trans('ConfirmDeleteLoan');
|
||||
print $form->formconfirm($_SERVER['PHP_SELF'].'?id='.$object->id,$langs->trans('DeleteLoan'),$text,'confirm_delete','','',2);
|
||||
}
|
||||
|
||||
if ($action == 'edit')
|
||||
{
|
||||
print "<form name=\"loan\" action=\"card.php?id=$object->id&action=update\" method=\"post\">";
|
||||
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
|
||||
}
|
||||
|
||||
print '<table class="border" width="100%">';
|
||||
|
||||
// Ref
|
||||
print '<tr><td width="25%">'.$langs->trans("Ref").'</td><td colspan="2">';
|
||||
print $form->showrefnav($object,'id');
|
||||
print "</td></tr>";
|
||||
|
||||
// Label
|
||||
if ($action == 'edit')
|
||||
{
|
||||
print '<tr><td>'.$langs->trans("Label").'</td><td colspan="2">';
|
||||
print '<input type="text" name="label" size="40" value="'.$object->label.'">';
|
||||
print '</td></tr>';
|
||||
}
|
||||
else
|
||||
{
|
||||
print '<tr><td>'.$langs->trans("Label").'</td><td colspan="2">'.$object->label.'</td></tr>';
|
||||
}
|
||||
|
||||
$rowspan=5;
|
||||
print '<td rowspan="'.$rowspan.'" valign="top">';
|
||||
|
||||
/*
|
||||
* Payments
|
||||
*/
|
||||
$sql = "SELECT p.rowid, p.num_payment, datep as dp, p.amount,";
|
||||
$sql.= "c.libelle as paiement_type";
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX."payment_loan as p";
|
||||
$sql.= ", ".MAIN_DB_PREFIX."c_paiement as c ";
|
||||
$sql.= ", ".MAIN_DB_PREFIX."loan as l";
|
||||
$sql.= " WHERE p.fk_loan = ".$id;
|
||||
$sql.= " AND p.fk_loan = l.rowid";
|
||||
$sql.= " AND l.entity = ".$conf->entity;
|
||||
$sql.= " AND p.fk_typepayment = c.id";
|
||||
$sql.= " ORDER BY dp DESC";
|
||||
|
||||
//print $sql;
|
||||
$resql = $db->query($sql);
|
||||
if ($resql)
|
||||
{
|
||||
$num = $db->num_rows($resql);
|
||||
$i = 0; $total = 0;
|
||||
echo '<table class="nobordernopadding" width="100%">';
|
||||
print '<tr class="liste_titre">';
|
||||
print '<td>'.$langs->trans("RefPayment").'</td>';
|
||||
print '<td>'.$langs->trans("Date").'</td>';
|
||||
print '<td>'.$langs->trans("Type").'</td>';
|
||||
print '<td align="right">'.$langs->trans("Amount").'</td>';
|
||||
print '<td> </td>';
|
||||
print '</tr>';
|
||||
|
||||
$var=True;
|
||||
while ($i < $num)
|
||||
{
|
||||
$objp = $db->fetch_object($resql);
|
||||
$var=!$var;
|
||||
print "<tr ".$bc[$var]."><td>";
|
||||
print '<a href="'.DOL_URL_ROOT.'/compta/payment_sc/fiche.php?id='.$objp->rowid.'">'.img_object($langs->trans("Payment"),"payment").' '.$objp->rowid.'</a></td>';
|
||||
print '<td>'.dol_print_date($db->jdate($objp->dp),'day')."</td>\n";
|
||||
print "<td>".$objp->paiement_type.' '.$objp->num_paiement."</td>\n";
|
||||
print '<td align="right">'.price($objp->amount)."</td><td> ".$langs->trans("Currency".$conf->currency)."</td>\n";
|
||||
print "</tr>";
|
||||
$totalpaye += $objp->amount;
|
||||
$i++;
|
||||
}
|
||||
|
||||
if ($object->paye == 0)
|
||||
{
|
||||
print "<tr><td colspan=\"2\" align=\"right\">".$langs->trans("AlreadyPaid")." :</td><td align=\"right\"><b>".price($totalpaye)."</b></td><td> ".$langs->trans("Currency".$conf->currency)."</td></tr>\n";
|
||||
print "<tr><td colspan=\"2\" align=\"right\">".$langs->trans("AmountExpected")." :</td><td align=\"right\" bgcolor=\"#d0d0d0\">".price($object->amount)."</td><td bgcolor=\"#d0d0d0\"> ".$langs->trans("Currency".$conf->currency)."</td></tr>\n";
|
||||
|
||||
$resteapayer = $object->amount - $totalpaye;
|
||||
|
||||
print "<tr><td colspan=\"2\" align=\"right\">".$langs->trans("RemainderToPay")." :</td>";
|
||||
print "<td align=\"right\" bgcolor=\"#f0f0f0\"><b>".price($resteapayer)."</b></td><td bgcolor=\"#f0f0f0\"> ".$langs->trans("Currency".$conf->currency)."</td></tr>\n";
|
||||
}
|
||||
print "</table>";
|
||||
$db->free($resql);
|
||||
}
|
||||
else
|
||||
{
|
||||
dol_print_error($db);
|
||||
}
|
||||
print "</td>";
|
||||
|
||||
print "</tr>";
|
||||
|
||||
// Period end date
|
||||
print "<tr><td>".$langs->trans("PeriodEndDate")."</td>";
|
||||
print "<td>";
|
||||
if ($action == 'edit')
|
||||
{
|
||||
print $form->select_date($object->periode, 'period', 0, 0, 0, 'charge', 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
print dol_print_date($object->periode,"day");
|
||||
}
|
||||
print "</td></tr>";
|
||||
|
||||
// Due date
|
||||
if ($action == 'edit')
|
||||
{
|
||||
print '<tr><td>'.$langs->trans("DateDue")."</td><td>";
|
||||
print $form->select_date($object->date_ech, 'ech', 0, 0, 0, 'charge', 1);
|
||||
print "</td></tr>";
|
||||
}
|
||||
else {
|
||||
print "<tr><td>".$langs->trans("DateDue")."</td><td>".dol_print_date($object->date_ech,'day')."</td></tr>";
|
||||
}
|
||||
|
||||
// Amount
|
||||
print '<tr><td>'.$langs->trans("AmountTTC").'</td><td>'.price($object->amount,0,$outputlangs,1,-1,-1,$conf->currency).'</td></tr>';
|
||||
|
||||
// Status
|
||||
print '<tr><td>'.$langs->trans("Status").'</td><td>'.$object->getLibStatut(4, $totalpaye).'</td></tr>';
|
||||
|
||||
print '</table>';
|
||||
|
||||
if ($action == 'edit')
|
||||
{
|
||||
print '<br><div align="center">';
|
||||
print '<input type="submit" class="button" name="save" value="'.$langs->trans("Save").'">';
|
||||
print ' ';
|
||||
print '<input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'">';
|
||||
print '</div';
|
||||
}
|
||||
|
||||
if ($action == 'edit') print "</form>\n";
|
||||
|
||||
dol_fiche_end();
|
||||
|
||||
|
||||
/*
|
||||
* Boutons actions
|
||||
*/
|
||||
if ($action != 'edit')
|
||||
{
|
||||
print "<div class=\"tabsAction\">\n";
|
||||
|
||||
// Edit
|
||||
if ($user->rights->loan->write)
|
||||
{
|
||||
print "<a class=\"butAction\" href=\"".DOL_URL_ROOT."/compta/sociales/charges.php?id=$object->id&action=edit\">".$langs->trans("Modify")."</a>";
|
||||
}
|
||||
|
||||
// Emettre paiement
|
||||
if ($object->paye == 0 && ((price2num($object->amount) < 0 && round($resteapayer) < 0) || (price2num($object->amount) > 0 && round($resteapayer) > 0)) && $user->rights->loan->write)
|
||||
{
|
||||
print "<a class=\"butAction\" href=\"".DOL_URL_ROOT."/compta/paiement_charge.php?id=$object->id&action=create\">".$langs->trans("DoPayment")."</a>";
|
||||
}
|
||||
|
||||
// Classify 'paid'
|
||||
if ($object->paye == 0 && round($resteapayer) <=0 && $user->rights->loan->write)
|
||||
{
|
||||
print "<a class=\"butAction\" href=\"".DOL_URL_ROOT."/compta/loan/card.php?id=$object->id&action=paid\">".$langs->trans("ClassifyPaid")."</a>";
|
||||
}
|
||||
|
||||
// Delete
|
||||
if ($user->rights->loan->delete)
|
||||
{
|
||||
print "<a class=\"butActionDelete\" href=\"".DOL_URL_ROOT."/compta/loan/card.php?id=$object->id&action=delete\">".$langs->trans("Delete")."</a>";
|
||||
}
|
||||
|
||||
print "</div>";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Loan not find
|
||||
dol_print_error('',$object->error);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
llxFooter();
|
||||
|
||||
$db->close();
|
||||
0
htdocs/compta/loan/class/index.html
Normal file
0
htdocs/compta/loan/class/index.html
Normal file
477
htdocs/compta/loan/class/loan.class.php
Normal file
477
htdocs/compta/loan/class/loan.class.php
Normal file
@ -0,0 +1,477 @@
|
||||
<?php
|
||||
/* Copyright (C) 2014 Alexandre Spangaro <alexandre.spangaro@gmail.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/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file htdocs/compta/loan/class/loan.class.php
|
||||
* \ingroup loan
|
||||
* \brief Class for loan module
|
||||
*/
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
|
||||
|
||||
|
||||
/** \class Loan
|
||||
* \brief Class to manage loan
|
||||
*/
|
||||
class Loan extends CommonObject
|
||||
{
|
||||
public $element='loan';
|
||||
public $table='loan';
|
||||
public $table_element='loan';
|
||||
|
||||
var $id;
|
||||
var $ref;
|
||||
var $date_start;
|
||||
var $dateend;
|
||||
var $label;
|
||||
var $capital;
|
||||
var $nbterm;
|
||||
var $rate;
|
||||
var $note;
|
||||
var $account_capital;
|
||||
var $account_insurance;
|
||||
var $account_interest;
|
||||
var $date_creation;
|
||||
var $date_modification;
|
||||
var $date_validation;
|
||||
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param DoliDB $db Database handler
|
||||
*/
|
||||
function __construct($db)
|
||||
{
|
||||
$this->db = $db;
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load object in memory from database
|
||||
*
|
||||
* @param int $id id object
|
||||
* @return void
|
||||
*/
|
||||
function fetch($id)
|
||||
{
|
||||
$sql = "SELECT l.rowid, l.datestart,";
|
||||
$sql.= " l.label, l.capital";
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX."loan as l";
|
||||
$sql.= " WHERE l.rowid = ".$id;
|
||||
|
||||
dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
|
||||
$resql=$this->db->query($sql);
|
||||
if ($resql)
|
||||
{
|
||||
if ($this->db->num_rows($resql))
|
||||
{
|
||||
$obj = $this->db->fetch_object($resql);
|
||||
|
||||
$this->id = $obj->rowid;
|
||||
$this->ref = $obj->rowid;
|
||||
$this->datestart = $this->db->jdate($obj->datestart);
|
||||
$this->label = $obj->label;
|
||||
$this->capital = $obj->capital;
|
||||
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
$this->db->free($resql);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->error=$this->db->lasterror();
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create a social contribution into database
|
||||
*
|
||||
* @param User $user User making creation
|
||||
* @return int <0 if KO, id if OK
|
||||
*/
|
||||
function create($user)
|
||||
{
|
||||
global $conf;
|
||||
|
||||
// clean parameters
|
||||
$newcapital=price2num($this->capital,'MT');
|
||||
|
||||
// Validation parametres
|
||||
if (! $newamount > 0 || empty($this->date_ech) || empty($this->periode))
|
||||
{
|
||||
$this->error="ErrorBadParameter";
|
||||
return -2;
|
||||
}
|
||||
|
||||
$this->db->begin();
|
||||
|
||||
$sql = "INSERT INTO ".MAIN_DB_PREFIX."chargesociales (fk_type, libelle, date_ech, periode, amount, entity)";
|
||||
$sql.= " VALUES (".$this->type.",'".$this->db->escape($this->lib)."',";
|
||||
$sql.= " '".$this->db->idate($this->date_ech)."','".$this->db->idate($this->periode)."',";
|
||||
$sql.= " '".price2num($newamount)."',";
|
||||
$sql.= " ".$conf->entity;
|
||||
$sql.= ")";
|
||||
|
||||
dol_syslog(get_class($this)."::create", LOG_DEBUG);
|
||||
$resql=$this->db->query($sql);
|
||||
if ($resql)
|
||||
{
|
||||
$this->id=$this->db->last_insert_id(MAIN_DB_PREFIX."chargesociales");
|
||||
|
||||
//dol_syslog("ChargesSociales::create this->id=".$this->id);
|
||||
$this->db->commit();
|
||||
return $this->id;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->error=$this->db->error();
|
||||
$this->db->rollback();
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Delete a social contribution
|
||||
*
|
||||
* @param User $user Object user making delete
|
||||
* @return int <0 if KO, >0 if OK
|
||||
*/
|
||||
function delete($user)
|
||||
{
|
||||
$error=0;
|
||||
|
||||
$this->db->begin();
|
||||
|
||||
// Get bank transaction lines for this social contributions
|
||||
include_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
|
||||
$account=new Account($this->db);
|
||||
$lines_url=$account->get_url('',$this->id,'sc');
|
||||
|
||||
// Delete bank urls
|
||||
foreach ($lines_url as $line_url)
|
||||
{
|
||||
if (! $error)
|
||||
{
|
||||
$accountline=new AccountLine($this->db);
|
||||
$accountline->fetch($line_url['fk_bank']);
|
||||
$result=$accountline->delete_urls($user);
|
||||
if ($result < 0)
|
||||
{
|
||||
$error++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Delete payments
|
||||
if (! $error)
|
||||
{
|
||||
$sql = "DELETE FROM ".MAIN_DB_PREFIX."paiementcharge where fk_charge='".$this->id."'";
|
||||
dol_syslog(get_class($this)."::delete", LOG_DEBUG);
|
||||
$resql=$this->db->query($sql);
|
||||
if (! $resql)
|
||||
{
|
||||
$error++;
|
||||
$this->error=$this->db->lasterror();
|
||||
}
|
||||
}
|
||||
|
||||
if (! $error)
|
||||
{
|
||||
$sql = "DELETE FROM ".MAIN_DB_PREFIX."chargesociales where rowid='".$this->id."'";
|
||||
dol_syslog(get_class($this)."::delete", LOG_DEBUG);
|
||||
$resql=$this->db->query($sql);
|
||||
if (! $resql)
|
||||
{
|
||||
$error++;
|
||||
$this->error=$this->db->lasterror();
|
||||
}
|
||||
}
|
||||
|
||||
if (! $error)
|
||||
{
|
||||
$this->db->commit();
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->db->rollback();
|
||||
return -1;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Met a jour une charge sociale
|
||||
*
|
||||
* @param User $user Utilisateur qui modifie
|
||||
* @return int <0 si erreur, >0 si ok
|
||||
*/
|
||||
function update($user)
|
||||
{
|
||||
$this->db->begin();
|
||||
|
||||
$sql = "UPDATE ".MAIN_DB_PREFIX."chargesociales";
|
||||
$sql.= " SET libelle='".$this->db->escape($this->lib)."',";
|
||||
$sql.= " date_ech='".$this->db->idate($this->date_ech)."',";
|
||||
$sql.= " periode='".$this->db->idate($this->periode)."'";
|
||||
$sql.= " WHERE rowid=".$this->id;
|
||||
|
||||
dol_syslog(get_class($this)."::update", LOG_DEBUG);
|
||||
$resql=$this->db->query($sql);
|
||||
if ($resql)
|
||||
{
|
||||
$this->db->commit();
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->error=$this->db->error();
|
||||
$this->db->rollback();
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Enter description here ...
|
||||
*
|
||||
* @param int $year Year
|
||||
* @return number
|
||||
*/
|
||||
function solde($year = 0)
|
||||
{
|
||||
global $conf;
|
||||
|
||||
$sql = "SELECT SUM(f.amount) as amount";
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX."chargesociales as f";
|
||||
$sql.= " WHERE f.entity = ".$conf->entity;
|
||||
$sql.= " AND paye = 0";
|
||||
|
||||
if ($year) {
|
||||
$sql .= " AND f.datev >= '$y-01-01' AND f.datev <= '$y-12-31' ";
|
||||
}
|
||||
|
||||
$result = $this->db->query($sql);
|
||||
if ($result)
|
||||
{
|
||||
if ($this->db->num_rows($result))
|
||||
{
|
||||
$obj = $this->db->fetch_object($result);
|
||||
return $obj->amount;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
$this->db->free($result);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
print $this->db->error();
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tag social contribution as payed completely
|
||||
*
|
||||
* @param User $user Object user making change
|
||||
* @return int <0 if KO, >0 if OK
|
||||
*/
|
||||
function set_paid($user)
|
||||
{
|
||||
$sql = "UPDATE ".MAIN_DB_PREFIX."chargesociales SET";
|
||||
$sql.= " paye = 1";
|
||||
$sql.= " WHERE rowid = ".$this->id;
|
||||
$return = $this->db->query($sql);
|
||||
if ($return) return 1;
|
||||
else return -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retourne le libelle du statut d'une charge (impaye, payee)
|
||||
*
|
||||
* @param int $mode 0=libelle long, 1=libelle court, 2=Picto + Libelle court, 3=Picto, 4=Picto + Libelle long
|
||||
* @param double $alreadypaid 0=No payment already done, >0=Some payments were already done (we recommand to put here amount payed if you have it, 1 otherwise)
|
||||
* @return string Label
|
||||
*/
|
||||
function getLibStatut($mode=0,$alreadypaid=-1)
|
||||
{
|
||||
return $this->LibStatut($this->paye,$mode,$alreadypaid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return label for given status
|
||||
*
|
||||
* @param int $statut Id statut
|
||||
* @param int $mode 0=libelle long, 1=libelle court, 2=Picto + Libelle court, 3=Picto, 4=Picto + Libelle long, 5=Libelle court + Picto
|
||||
* @param double $alreadypaid 0=No payment already done, >0=Some payments were already done (we recommand to put here amount payed if you have it, 1 otherwise)
|
||||
* @return string Label
|
||||
*/
|
||||
function LibStatut($statut,$mode=0,$alreadypaid=-1)
|
||||
{
|
||||
global $langs;
|
||||
$langs->load('customers');
|
||||
$langs->load('bills');
|
||||
|
||||
if ($mode == 0)
|
||||
{
|
||||
if ($statut == 0) return $langs->trans("Unpaid");
|
||||
if ($statut == 1) return $langs->trans("Paid");
|
||||
}
|
||||
if ($mode == 1)
|
||||
{
|
||||
if ($statut == 0) return $langs->trans("Unpaid");
|
||||
if ($statut == 1) return $langs->trans("Paid");
|
||||
}
|
||||
if ($mode == 2)
|
||||
{
|
||||
if ($statut == 0 && $alreadypaid <= 0) return img_picto($langs->trans("Unpaid"), 'statut1').' '.$langs->trans("Unpaid");
|
||||
if ($statut == 0 && $alreadypaid > 0) return img_picto($langs->trans("BillStatusStarted"), 'statut3').' '.$langs->trans("BillStatusStarted");
|
||||
if ($statut == 1) return img_picto($langs->trans("Paid"), 'statut6').' '.$langs->trans("Paid");
|
||||
}
|
||||
if ($mode == 3)
|
||||
{
|
||||
if ($statut == 0 && $alreadypaid <= 0) return img_picto($langs->trans("Unpaid"), 'statut1');
|
||||
if ($statut == 0 && $alreadypaid > 0) return img_picto($langs->trans("BillStatusStarted"), 'statut3');
|
||||
if ($statut == 1) return img_picto($langs->trans("Paid"), 'statut6');
|
||||
}
|
||||
if ($mode == 4)
|
||||
{
|
||||
if ($statut == 0 && $alreadypaid <= 0) return img_picto($langs->trans("Unpaid"), 'statut1').' '.$langs->trans("Unpaid");
|
||||
if ($statut == 0 && $alreadypaid > 0) return img_picto($langs->trans("BillStatusStarted"), 'statut3').' '.$langs->trans("BillStatusStarted");
|
||||
if ($statut == 1) return img_picto($langs->trans("Paid"), 'statut6').' '.$langs->trans("Paid");
|
||||
}
|
||||
if ($mode == 5)
|
||||
{
|
||||
if ($statut == 0 && $alreadypaid <= 0) return $langs->trans("Unpaid").' '.img_picto($langs->trans("Unpaid"), 'statut1');
|
||||
if ($statut == 0 && $alreadypaid > 0) return $langs->trans("BillStatusStarted").' '.img_picto($langs->trans("BillStatusStarted"), 'statut3');
|
||||
if ($statut == 1) return $langs->trans("Paid").' '.img_picto($langs->trans("Paid"), 'statut6');
|
||||
}
|
||||
|
||||
return "Error, mode/status not found";
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return clicable name (with eventually the picto)
|
||||
*
|
||||
* @param int $withpicto 0=No picto, 1=Include picto into link, 2=Only picto
|
||||
* @param int $maxlen Label max length
|
||||
* @return string Chaine with URL
|
||||
*/
|
||||
function getNameUrl($withpicto=0,$maxlen=0)
|
||||
{
|
||||
global $langs;
|
||||
|
||||
$result='';
|
||||
|
||||
if (empty($this->ref)) $this->ref=$this->lib;
|
||||
|
||||
$lien = '<a href="'.DOL_URL_ROOT.'/compta/loan/card.php?id='.$this->id.'">';
|
||||
$lienfin='</a>';
|
||||
|
||||
if ($withpicto) $result.=($lien.img_object($langs->trans("ShowSocialContribution").': '.$this->lib,'bill').$lienfin.' ');
|
||||
if ($withpicto && $withpicto != 2) $result.=' ';
|
||||
if ($withpicto != 2) $result.=$lien.($maxlen?dol_trunc($this->ref,$maxlen):$this->ref).$lienfin;
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return amount of payments already done
|
||||
*
|
||||
* @return int Amount of payment already done, <0 if KO
|
||||
*/
|
||||
function getSumPayment()
|
||||
{
|
||||
$table='payment_loan';
|
||||
$field='fk_loan';
|
||||
|
||||
$sql = 'SELECT sum(amount) as amount';
|
||||
$sql.= ' FROM '.MAIN_DB_PREFIX.$table;
|
||||
$sql.= ' WHERE '.$field.' = '.$this->id;
|
||||
|
||||
dol_syslog(get_class($this)."::getSumPayment", LOG_DEBUG);
|
||||
$resql=$this->db->query($sql);
|
||||
if ($resql)
|
||||
{
|
||||
$amount=0;
|
||||
|
||||
$obj = $this->db->fetch_object($resql);
|
||||
if ($obj) $amount=$obj->amount?$obj->amount:0;
|
||||
|
||||
$this->db->free($resql);
|
||||
return $amount;
|
||||
}
|
||||
else
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Information on record
|
||||
*
|
||||
* @param int $id Id of record
|
||||
* @return void
|
||||
*/
|
||||
function info($id)
|
||||
{
|
||||
$sql = "SELECT l.rowid, l.tms as datem, l.datec as datec";
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX."loan as l";
|
||||
$sql.= " WHERE l.rowid = ".$id;
|
||||
|
||||
dol_syslog(get_class($this)."::info", LOG_DEBUG);
|
||||
$result=$this->db->query($sql);
|
||||
if ($result)
|
||||
{
|
||||
if ($this->db->num_rows($result))
|
||||
{
|
||||
$obj = $this->db->fetch_object($result);
|
||||
|
||||
$this->id = $obj->rowid;
|
||||
|
||||
if ($obj->fk_user_author) {
|
||||
$cuser = new User($this->db);
|
||||
$cuser->fetch($obj->fk_user_author);
|
||||
$this->user_creation = $cuser;
|
||||
}
|
||||
|
||||
$this->date_creation = $this->db->jdate($obj->datec);
|
||||
$this->date_modification = $this->db->jdate($obj->datem);
|
||||
|
||||
}
|
||||
|
||||
$this->db->free($result);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
dol_print_error($this->db);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
603
htdocs/compta/loan/class/paymentloan.class.php
Normal file
603
htdocs/compta/loan/class/paymentloan.class.php
Normal file
@ -0,0 +1,603 @@
|
||||
<?php
|
||||
/* Copyright (C) 2002 Rodolphe Quiedeville <rodolphe@quiedeville.org>
|
||||
* Copyright (C) 2004-2007 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||
*
|
||||
* 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/compta/sociales/class/paymentsocialcontribution.class.php
|
||||
* \ingroup facture
|
||||
* \brief File of class to manage payment of social contributions
|
||||
*/
|
||||
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
|
||||
|
||||
|
||||
/** \class PaymentSocialContribution
|
||||
* \brief Class to manage payments of social contributions
|
||||
*/
|
||||
class PaymentSocialContribution extends CommonObject
|
||||
{
|
||||
public $element='paiementcharge'; //!< Id that identify managed objects
|
||||
public $table_element='paiementcharge'; //!< Name of table without prefix where object is stored
|
||||
|
||||
var $id;
|
||||
var $ref;
|
||||
|
||||
var $fk_charge;
|
||||
var $datec='';
|
||||
var $tms='';
|
||||
var $datep='';
|
||||
var $amount; // Total amount of payment
|
||||
var $amounts=array(); // Array of amounts
|
||||
var $fk_typepaiement;
|
||||
var $num_paiement;
|
||||
var $note;
|
||||
var $fk_bank;
|
||||
var $fk_user_creat;
|
||||
var $fk_user_modif;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param DoliDB $db Database handler
|
||||
*/
|
||||
function __construct($db)
|
||||
{
|
||||
$this->db = $db;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create payment of social contribution into database.
|
||||
* Use this->amounts to have list of lines for the payment
|
||||
*
|
||||
* @param User $user User making payment
|
||||
* @return int <0 if KO, id of payment if OK
|
||||
*/
|
||||
function create($user)
|
||||
{
|
||||
global $conf, $langs;
|
||||
|
||||
$error=0;
|
||||
|
||||
$now=dol_now();
|
||||
|
||||
// Validate parametres
|
||||
if (! $this->datepaye)
|
||||
{
|
||||
$this->error='ErrorBadValueForParameter';
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Clean parameters
|
||||
if (isset($this->fk_charge)) $this->fk_charge=trim($this->fk_charge);
|
||||
if (isset($this->amount)) $this->amount=trim($this->amount);
|
||||
if (isset($this->fk_typepaiement)) $this->fk_typepaiement=trim($this->fk_typepaiement);
|
||||
if (isset($this->num_paiement)) $this->num_paiement=trim($this->num_paiement);
|
||||
if (isset($this->note)) $this->note=trim($this->note);
|
||||
if (isset($this->fk_bank)) $this->fk_bank=trim($this->fk_bank);
|
||||
if (isset($this->fk_user_creat)) $this->fk_user_creat=trim($this->fk_user_creat);
|
||||
if (isset($this->fk_user_modif)) $this->fk_user_modif=trim($this->fk_user_modif);
|
||||
|
||||
$totalamount = 0;
|
||||
foreach ($this->amounts as $key => $value) // How payment is dispatch
|
||||
{
|
||||
$newvalue = price2num($value,'MT');
|
||||
$this->amounts[$key] = $newvalue;
|
||||
$totalamount += $newvalue;
|
||||
}
|
||||
$totalamount = price2num($totalamount);
|
||||
|
||||
// Check parameters
|
||||
if ($totalamount == 0) return -1; // On accepte les montants negatifs pour les rejets de prelevement mais pas null
|
||||
|
||||
|
||||
$this->db->begin();
|
||||
|
||||
if ($totalamount != 0)
|
||||
{
|
||||
$sql = "INSERT INTO ".MAIN_DB_PREFIX."paiementcharge (fk_charge, datec, datep, amount,";
|
||||
$sql.= " fk_typepaiement, num_paiement, note, fk_user_creat, fk_bank)";
|
||||
$sql.= " VALUES ($this->chid, '".$this->db->idate($now)."',";
|
||||
$sql.= " '".$this->db->idate($this->datepaye)."',";
|
||||
$sql.= " ".$totalamount.",";
|
||||
$sql.= " ".$this->paiementtype.", '".$this->db->escape($this->num_paiement)."', '".$this->db->escape($this->note)."', ".$user->id.",";
|
||||
$sql.= " 0)";
|
||||
|
||||
dol_syslog(get_class($this)."::create", LOG_DEBUG);
|
||||
$resql=$this->db->query($sql);
|
||||
if ($resql)
|
||||
{
|
||||
$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."paiementcharge");
|
||||
}
|
||||
else
|
||||
{
|
||||
$error++;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if ($totalamount != 0 && ! $error)
|
||||
{
|
||||
$this->amount=$totalamount;
|
||||
$this->total=$totalamount; // deprecated
|
||||
$this->db->commit();
|
||||
return $this->id;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->error=$this->db->error();
|
||||
$this->db->rollback();
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Load object in memory from database
|
||||
*
|
||||
* @param int $id Id object
|
||||
* @return int <0 if KO, >0 if OK
|
||||
*/
|
||||
function fetch($id)
|
||||
{
|
||||
global $langs;
|
||||
$sql = "SELECT";
|
||||
$sql.= " t.rowid,";
|
||||
$sql.= " t.fk_charge,";
|
||||
$sql.= " t.datec,";
|
||||
$sql.= " t.tms,";
|
||||
$sql.= " t.datep,";
|
||||
$sql.= " t.amount,";
|
||||
$sql.= " t.fk_typepaiement,";
|
||||
$sql.= " t.num_paiement,";
|
||||
$sql.= " t.note,";
|
||||
$sql.= " t.fk_bank,";
|
||||
$sql.= " t.fk_user_creat,";
|
||||
$sql.= " t.fk_user_modif,";
|
||||
$sql.= " pt.code as type_code, pt.libelle as type_libelle,";
|
||||
$sql.= ' b.fk_account';
|
||||
$sql.= " FROM (".MAIN_DB_PREFIX."c_paiement as pt, ".MAIN_DB_PREFIX."paiementcharge as t)";
|
||||
$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'bank as b ON t.fk_bank = b.rowid';
|
||||
$sql.= " WHERE t.rowid = ".$id." AND t.fk_typepaiement = pt.id";
|
||||
|
||||
dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
|
||||
$resql=$this->db->query($sql);
|
||||
if ($resql)
|
||||
{
|
||||
if ($this->db->num_rows($resql))
|
||||
{
|
||||
$obj = $this->db->fetch_object($resql);
|
||||
|
||||
$this->id = $obj->rowid;
|
||||
$this->ref = $obj->rowid;
|
||||
|
||||
$this->fk_charge = $obj->fk_charge;
|
||||
$this->datec = $this->db->jdate($obj->datec);
|
||||
$this->tms = $this->db->jdate($obj->tms);
|
||||
$this->datep = $this->db->jdate($obj->datep);
|
||||
$this->amount = $obj->amount;
|
||||
$this->fk_typepaiement = $obj->fk_typepaiement;
|
||||
$this->num_paiement = $obj->num_paiement;
|
||||
$this->note = $obj->note;
|
||||
$this->fk_bank = $obj->fk_bank;
|
||||
$this->fk_user_creat = $obj->fk_user_creat;
|
||||
$this->fk_user_modif = $obj->fk_user_modif;
|
||||
|
||||
$this->type_code = $obj->type_code;
|
||||
$this->type_libelle = $obj->type_libelle;
|
||||
|
||||
$this->bank_account = $obj->fk_account;
|
||||
$this->bank_line = $obj->fk_bank;
|
||||
}
|
||||
$this->db->free($resql);
|
||||
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->error="Error ".$this->db->lasterror();
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Update database
|
||||
*
|
||||
* @param User $user User that modify
|
||||
* @param int $notrigger 0=launch triggers after, 1=disable triggers
|
||||
* @return int <0 if KO, >0 if OK
|
||||
*/
|
||||
function update($user=0, $notrigger=0)
|
||||
{
|
||||
global $conf, $langs;
|
||||
$error=0;
|
||||
|
||||
// Clean parameters
|
||||
|
||||
if (isset($this->fk_charge)) $this->fk_charge=trim($this->fk_charge);
|
||||
if (isset($this->amount)) $this->amount=trim($this->amount);
|
||||
if (isset($this->fk_typepaiement)) $this->fk_typepaiement=trim($this->fk_typepaiement);
|
||||
if (isset($this->num_paiement)) $this->num_paiement=trim($this->num_paiement);
|
||||
if (isset($this->note)) $this->note=trim($this->note);
|
||||
if (isset($this->fk_bank)) $this->fk_bank=trim($this->fk_bank);
|
||||
if (isset($this->fk_user_creat)) $this->fk_user_creat=trim($this->fk_user_creat);
|
||||
if (isset($this->fk_user_modif)) $this->fk_user_modif=trim($this->fk_user_modif);
|
||||
|
||||
|
||||
|
||||
// Check parameters
|
||||
// Put here code to add control on parameters values
|
||||
|
||||
// Update request
|
||||
$sql = "UPDATE ".MAIN_DB_PREFIX."paiementcharge SET";
|
||||
|
||||
$sql.= " fk_charge=".(isset($this->fk_charge)?$this->fk_charge:"null").",";
|
||||
$sql.= " datec=".(dol_strlen($this->datec)!=0 ? "'".$this->db->idate($this->datec)."'" : 'null').",";
|
||||
$sql.= " tms=".(dol_strlen($this->tms)!=0 ? "'".$this->db->idate($this->tms)."'" : 'null').",";
|
||||
$sql.= " datep=".(dol_strlen($this->datep)!=0 ? "'".$this->db->idate($this->datep)."'" : 'null').",";
|
||||
$sql.= " amount=".(isset($this->amount)?$this->amount:"null").",";
|
||||
$sql.= " fk_typepaiement=".(isset($this->fk_typepaiement)?$this->fk_typepaiement:"null").",";
|
||||
$sql.= " num_paiement=".(isset($this->num_paiement)?"'".$this->db->escape($this->num_paiement)."'":"null").",";
|
||||
$sql.= " note=".(isset($this->note)?"'".$this->db->escape($this->note)."'":"null").",";
|
||||
$sql.= " fk_bank=".(isset($this->fk_bank)?$this->fk_bank:"null").",";
|
||||
$sql.= " fk_user_creat=".(isset($this->fk_user_creat)?$this->fk_user_creat:"null").",";
|
||||
$sql.= " fk_user_modif=".(isset($this->fk_user_modif)?$this->fk_user_modif:"null")."";
|
||||
|
||||
|
||||
$sql.= " WHERE rowid=".$this->id;
|
||||
|
||||
$this->db->begin();
|
||||
|
||||
dol_syslog(get_class($this)."::update", LOG_DEBUG);
|
||||
$resql = $this->db->query($sql);
|
||||
if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); }
|
||||
|
||||
if (! $error)
|
||||
{
|
||||
if (! $notrigger)
|
||||
{
|
||||
// Uncomment this and change MYOBJECT to your own tag if you
|
||||
// want this action call a trigger.
|
||||
|
||||
//// Call triggers
|
||||
//include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php';
|
||||
//$interface=new Interfaces($this->db);
|
||||
//$result=$interface->run_triggers('MYOBJECT_MODIFY',$this,$user,$langs,$conf);
|
||||
//if ($result < 0) { $error++; $this->errors=$interface->errors; }
|
||||
//// End call triggers
|
||||
}
|
||||
}
|
||||
|
||||
// Commit or rollback
|
||||
if ($error)
|
||||
{
|
||||
foreach($this->errors as $errmsg)
|
||||
{
|
||||
dol_syslog(get_class($this)."::update ".$errmsg, LOG_ERR);
|
||||
$this->error.=($this->error?', '.$errmsg:$errmsg);
|
||||
}
|
||||
$this->db->rollback();
|
||||
return -1*$error;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->db->commit();
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Delete object in database
|
||||
*
|
||||
* @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)
|
||||
{
|
||||
global $conf, $langs;
|
||||
$error=0;
|
||||
|
||||
$this->db->begin();
|
||||
|
||||
if (! $error)
|
||||
{
|
||||
$sql = "DELETE FROM ".MAIN_DB_PREFIX."bank_url";
|
||||
$sql.= " WHERE type='payment_sc' AND url_id=".$this->id;
|
||||
|
||||
dol_syslog(get_class($this)."::delete", LOG_DEBUG);
|
||||
$resql = $this->db->query($sql);
|
||||
if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); }
|
||||
}
|
||||
|
||||
if (! $error)
|
||||
{
|
||||
$sql = "DELETE FROM ".MAIN_DB_PREFIX."paiementcharge";
|
||||
$sql.= " WHERE rowid=".$this->id;
|
||||
|
||||
dol_syslog(get_class($this)."::delete", LOG_DEBUG);
|
||||
$resql = $this->db->query($sql);
|
||||
if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); }
|
||||
}
|
||||
|
||||
if (! $error)
|
||||
{
|
||||
if (! $notrigger)
|
||||
{
|
||||
// Uncomment this and change MYOBJECT to your own tag if you
|
||||
// want this action call a trigger.
|
||||
|
||||
//// Call triggers
|
||||
//include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php';
|
||||
//$interface=new Interfaces($this->db);
|
||||
//$result=$interface->run_triggers('MYOBJECT_DELETE',$this,$user,$langs,$conf);
|
||||
//if ($result < 0) { $error++; $this->errors=$interface->errors; }
|
||||
//// End call triggers
|
||||
}
|
||||
}
|
||||
|
||||
// Commit or rollback
|
||||
if ($error)
|
||||
{
|
||||
foreach($this->errors as $errmsg)
|
||||
{
|
||||
dol_syslog(get_class($this)."::delete ".$errmsg, LOG_ERR);
|
||||
$this->error.=($this->error?', '.$errmsg:$errmsg);
|
||||
}
|
||||
$this->db->rollback();
|
||||
return -1*$error;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->db->commit();
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Load an object from its id and create a new one in database
|
||||
*
|
||||
* @param int $fromid Id of object to clone
|
||||
* @return int New id of clone
|
||||
*/
|
||||
function createFromClone($fromid)
|
||||
{
|
||||
global $user,$langs;
|
||||
|
||||
$error=0;
|
||||
|
||||
$object=new PaymentSocialContribution($this->db);
|
||||
|
||||
$this->db->begin();
|
||||
|
||||
// Load source object
|
||||
$object->fetch($fromid);
|
||||
$object->id=0;
|
||||
$object->statut=0;
|
||||
|
||||
// Clear fields
|
||||
// ...
|
||||
|
||||
// Create clone
|
||||
$result=$object->create($user);
|
||||
|
||||
// Other options
|
||||
if ($result < 0)
|
||||
{
|
||||
$this->error=$object->error;
|
||||
$error++;
|
||||
}
|
||||
|
||||
if (! $error)
|
||||
{
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
// End
|
||||
if (! $error)
|
||||
{
|
||||
$this->db->commit();
|
||||
return $object->id;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->db->rollback();
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Initialise an instance with random values.
|
||||
* Used to build previews or test instances.
|
||||
* id must be 0 if object instance is a specimen.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function initAsSpecimen()
|
||||
{
|
||||
$this->id=0;
|
||||
|
||||
$this->fk_charge='';
|
||||
$this->datec='';
|
||||
$this->tms='';
|
||||
$this->datep='';
|
||||
$this->amount='';
|
||||
$this->fk_typepaiement='';
|
||||
$this->num_paiement='';
|
||||
$this->note='';
|
||||
$this->fk_bank='';
|
||||
$this->fk_user_creat='';
|
||||
$this->fk_user_modif='';
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Add record into bank for payment with links between this bank record and invoices of payment.
|
||||
* All payment properties must have been set first like after a call to create().
|
||||
*
|
||||
* @param User $user Object of user making payment
|
||||
* @param string $mode 'payment_sc'
|
||||
* @param string $label Label to use in bank record
|
||||
* @param int $accountid Id of bank account to do link with
|
||||
* @param string $emetteur_nom Name of transmitter
|
||||
* @param string $emetteur_banque Name of bank
|
||||
* @return int <0 if KO, >0 if OK
|
||||
*/
|
||||
function addPaymentToBank($user,$mode,$label,$accountid,$emetteur_nom,$emetteur_banque)
|
||||
{
|
||||
global $conf;
|
||||
|
||||
$error=0;
|
||||
|
||||
if (! empty($conf->banque->enabled))
|
||||
{
|
||||
require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
|
||||
|
||||
$acc = new Account($this->db);
|
||||
$acc->fetch($accountid);
|
||||
|
||||
$total=$this->total;
|
||||
if ($mode == 'payment_sc') $total=-$total;
|
||||
|
||||
// Insert payment into llx_bank
|
||||
$bank_line_id = $acc->addline(
|
||||
$this->datepaye,
|
||||
$this->paiementtype, // Payment mode id or code ("CHQ or VIR for example")
|
||||
$label,
|
||||
$total,
|
||||
$this->num_paiement,
|
||||
'',
|
||||
$user,
|
||||
$emetteur_nom,
|
||||
$emetteur_banque
|
||||
);
|
||||
|
||||
// Mise a jour fk_bank dans llx_paiement.
|
||||
// On connait ainsi le paiement qui a genere l'ecriture bancaire
|
||||
if ($bank_line_id > 0)
|
||||
{
|
||||
$result=$this->update_fk_bank($bank_line_id);
|
||||
if ($result <= 0)
|
||||
{
|
||||
$error++;
|
||||
dol_print_error($this->db);
|
||||
}
|
||||
|
||||
// Add link 'payment', 'payment_supplier', 'payment_sc' in bank_url between payment and bank transaction
|
||||
$url='';
|
||||
if ($mode == 'payment_sc') $url=DOL_URL_ROOT.'/compta/payment_sc/fiche.php?id=';
|
||||
if ($url)
|
||||
{
|
||||
$result=$acc->add_url_line($bank_line_id, $this->id, $url, '(paiement)', $mode);
|
||||
if ($result <= 0)
|
||||
{
|
||||
$error++;
|
||||
dol_print_error($this->db);
|
||||
}
|
||||
}
|
||||
|
||||
// Add link 'company' in bank_url between invoice and bank transaction (for each invoice concerned by payment)
|
||||
$linkaddedforthirdparty=array();
|
||||
foreach ($this->amounts as $key => $value)
|
||||
{
|
||||
if ($mode == 'payment_sc')
|
||||
{
|
||||
$socialcontrib = new ChargeSociales($this->db);
|
||||
$socialcontrib->fetch($key);
|
||||
$result=$acc->add_url_line($bank_line_id, $socialcontrib->id, DOL_URL_ROOT.'/compta/charges.php?id=', $socialcontrib->type_libelle.(($socialcontrib->lib && $socialcontrib->lib!=$socialcontrib->type_libelle)?' ('.$socialcontrib->lib.')':''),'sc');
|
||||
if ($result <= 0) dol_print_error($this->db);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->error=$acc->error;
|
||||
$error++;
|
||||
}
|
||||
}
|
||||
|
||||
if (! $error)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Mise a jour du lien entre le paiement de charge et la ligne dans llx_bank generee
|
||||
*
|
||||
* @param int $id_bank Id if bank
|
||||
* @return int >0 if OK, <=0 if KO
|
||||
*/
|
||||
function update_fk_bank($id_bank)
|
||||
{
|
||||
$sql = "UPDATE ".MAIN_DB_PREFIX."paiementcharge SET fk_bank = ".$id_bank." WHERE rowid = ".$this->id;
|
||||
|
||||
dol_syslog(get_class($this)."::update_fk_bank", LOG_DEBUG);
|
||||
$result = $this->db->query($sql);
|
||||
if ($result)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->error=$this->db->error();
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Renvoie nom clicable (avec eventuellement le picto)
|
||||
*
|
||||
* @param int $withpicto 0=Pas de picto, 1=Inclut le picto dans le lien, 2=Picto seul
|
||||
* @param int $maxlen Longueur max libelle
|
||||
* @return string Chaine avec URL
|
||||
*/
|
||||
function getNomUrl($withpicto=0,$maxlen=0)
|
||||
{
|
||||
global $langs;
|
||||
|
||||
$result='';
|
||||
|
||||
if (empty($this->ref)) $this->ref=$this->lib;
|
||||
|
||||
if (!empty($this->id))
|
||||
{
|
||||
$lien = '<a href="'.DOL_URL_ROOT.'/compta/payment_sc/fiche.php?id='.$this->id.'">';
|
||||
$lienfin='</a>';
|
||||
|
||||
if ($withpicto) $result.=($lien.img_object($langs->trans("ShowPayment").': '.$this->ref,'payment').$lienfin.' ');
|
||||
if ($withpicto && $withpicto != 2) $result.=' ';
|
||||
if ($withpicto != 2) $result.=$lien.($maxlen?dol_trunc($this->ref,$maxlen):$this->ref).$lienfin;
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
178
htdocs/compta/loan/document.php
Normal file
178
htdocs/compta/loan/document.php
Normal file
@ -0,0 +1,178 @@
|
||||
<?php
|
||||
/* Copyright (C) 2003-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
|
||||
* Copyright (C) 2004-2014 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||
* Copyright (C) 2005 Marc Barilley / Ocebo <marc@ocebo.com>
|
||||
* Copyright (C) 2005-2009 Regis Houssin <regis.houssin@capnetworks.com>
|
||||
* Copyright (C) 2005 Simon TOSSER <simon@kornog-computing.com>
|
||||
* Copyright (C) 2011 Juanjo Menent <jmenent@2byte.es>
|
||||
* Copyright (C) 2013 Cédric Salvador <csalvador@gpcsolutions.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/compta/sociales/document.php
|
||||
* \ingroup tax
|
||||
* \brief Page with attached files on social contributions
|
||||
*/
|
||||
|
||||
require '../../main.inc.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/compta/sociales/class/chargesociales.class.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/lib/tax.lib.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
|
||||
|
||||
$langs->load("other");
|
||||
$langs->load("companies");
|
||||
$langs->load("compta");
|
||||
$langs->load("bills");
|
||||
|
||||
$id = GETPOST('id','int');
|
||||
$action = GETPOST("action");
|
||||
$confirm = GETPOST('confirm', 'alpha');
|
||||
|
||||
// Security check
|
||||
if ($user->societe_id) $socid=$user->societe_id;
|
||||
$result = restrictedArea($user, 'tax', $id, 'chargesociales','charges');
|
||||
|
||||
|
||||
// Get parameters
|
||||
$sortfield = GETPOST("sortfield",'alpha');
|
||||
$sortorder = GETPOST("sortorder",'alpha');
|
||||
$page = GETPOST("page",'int');
|
||||
if ($page == -1) {
|
||||
$page = 0;
|
||||
}
|
||||
$offset = $conf->liste_limit * $page;
|
||||
$pageprev = $page - 1;
|
||||
$pagenext = $page + 1;
|
||||
if (! $sortorder) $sortorder="ASC";
|
||||
if (! $sortfield) $sortfield="name";
|
||||
|
||||
|
||||
$object = new ChargeSociales($db);
|
||||
if ($id > 0) $object->fetch($id);
|
||||
|
||||
$upload_dir = $conf->tax->dir_output.'/'.dol_sanitizeFileName($object->ref);
|
||||
$modulepart='tax';
|
||||
|
||||
|
||||
/*
|
||||
* Actions
|
||||
*/
|
||||
|
||||
include_once DOL_DOCUMENT_ROOT . '/core/tpl/document_actions_pre_headers.tpl.php';
|
||||
|
||||
|
||||
/*
|
||||
* View
|
||||
*/
|
||||
|
||||
$form = new Form($db);
|
||||
|
||||
$help_url='EN:Module_Taxes_and_social_contributions|FR:Module Taxes et dividendes|ES:Módulo Impuestos y cargas sociales (IVA, impuestos)';
|
||||
llxHeader("",$langs->trans("SocialContribution"),$help_url);
|
||||
|
||||
if ($object->id)
|
||||
{
|
||||
$alreadypayed=$object->getSommePaiement();
|
||||
|
||||
$head=tax_prepare_head($object, $user);
|
||||
|
||||
dol_fiche_head($head, 'documents', $langs->trans("SocialContribution"), 0, 'bill');
|
||||
|
||||
|
||||
// Construit liste des fichiers
|
||||
$filearray=dol_dir_list($upload_dir,"files",0,'','(\.meta|_preview\.png)$',$sortfield,(strtolower($sortorder)=='desc'?SORT_DESC:SORT_ASC),1);
|
||||
$totalsize=0;
|
||||
foreach($filearray as $key => $file)
|
||||
{
|
||||
$totalsize+=$file['size'];
|
||||
}
|
||||
|
||||
|
||||
print '<table class="border" width="100%">';
|
||||
|
||||
// Ref
|
||||
print '<tr><td width="25%">'.$langs->trans("Ref").'</td><td>';
|
||||
print $form->showrefnav($object,'id');
|
||||
print "</td></tr>";
|
||||
|
||||
// Label
|
||||
if ($action == 'edit')
|
||||
{
|
||||
print '<tr><td>'.$langs->trans("Label").'</td><td>';
|
||||
print '<input type="text" name="label" size="40" value="'.$object->lib.'">';
|
||||
print '</td></tr>';
|
||||
}
|
||||
else
|
||||
{
|
||||
print '<tr><td>'.$langs->trans("Label").'</td><td>'.$object->lib.'</td></tr>';
|
||||
}
|
||||
|
||||
// Type
|
||||
print "<tr><td>".$langs->trans("Type")."</td><td>".$object->type_libelle."</td></tr>";
|
||||
|
||||
// Period end date
|
||||
print "<tr><td>".$langs->trans("PeriodEndDate")."</td>";
|
||||
print "<td>";
|
||||
if ($action == 'edit')
|
||||
{
|
||||
print $form->select_date($object->periode, 'period', 0, 0, 0, 'charge', 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
print dol_print_date($object->periode,"day");
|
||||
}
|
||||
print "</td>";
|
||||
print "</tr>";
|
||||
|
||||
// Due date
|
||||
if ($action == 'edit')
|
||||
{
|
||||
print '<tr><td>'.$langs->trans("DateDue")."</td><td>";
|
||||
print $form->select_date($object->date_ech, 'ech', 0, 0, 0, 'charge', 1);
|
||||
print "</td></tr>";
|
||||
}
|
||||
else {
|
||||
print "<tr><td>".$langs->trans("DateDue")."</td><td>".dol_print_date($object->date_ech,'day')."</td></tr>";
|
||||
}
|
||||
|
||||
// Amount
|
||||
print '<tr><td>'.$langs->trans("AmountTTC").'</td><td>'.price($object->amount,0,$outputlangs,1,-1,-1,$conf->currency).'</td></tr>';
|
||||
|
||||
// Status
|
||||
print '<tr><td>'.$langs->trans("Status").'</td><td>'.$object->getLibStatut(4,$alreadypayed).'</td></tr>';
|
||||
|
||||
print '<tr><td>'.$langs->trans("NbOfAttachedFiles").'</td><td colspan="3">'.count($filearray).'</td></tr>';
|
||||
print '<tr><td>'.$langs->trans("TotalSizeOfAttachedFiles").'</td><td colspan="3">'.$totalsize.' '.$langs->trans("bytes").'</td></tr>';
|
||||
print '</table>';
|
||||
|
||||
print '</div>';
|
||||
|
||||
$modulepart = 'tax';
|
||||
$permission = $user->rights->tax->charges->creer;
|
||||
$param = '&id=' . $object->id;
|
||||
include_once DOL_DOCUMENT_ROOT . '/core/tpl/document_actions_post_headers.tpl.php';
|
||||
}
|
||||
else
|
||||
{
|
||||
print $langs->trans("ErrorUnknown");
|
||||
}
|
||||
|
||||
|
||||
llxFooter();
|
||||
|
||||
$db->close();
|
||||
0
htdocs/compta/loan/index.html
Normal file
0
htdocs/compta/loan/index.html
Normal file
208
htdocs/compta/loan/index.php
Normal file
208
htdocs/compta/loan/index.php
Normal file
@ -0,0 +1,208 @@
|
||||
<?php
|
||||
/* Copyright (C) 2014 Alexandre Spangaro <alexandre.spangaro@gmail.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/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file htdocs/compta/loan/index.php
|
||||
* \ingroup loan
|
||||
* \brief Page to list all loans
|
||||
*/
|
||||
|
||||
require '../../main.inc.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/compta/loan/class/loan.class.php';
|
||||
|
||||
$langs->load("loan");
|
||||
$langs->load("compta");
|
||||
$langs->load("banks");
|
||||
$langs->load("bills");
|
||||
|
||||
// Security check
|
||||
$socid = isset($_GET["socid"])?$_GET["socid"]:'';
|
||||
if ($user->societe_id) $socid=$user->societe_id;
|
||||
$result = restrictedArea($user, 'loan', '', '', '');
|
||||
|
||||
$sortfield = GETPOST("sortfield",'alpha');
|
||||
$sortorder = GETPOST("sortorder",'alpha');
|
||||
$page = GETPOST("page",'int');
|
||||
if ($page == -1) { $page = 0; }
|
||||
$offset = $conf->liste_limit * $page;
|
||||
$pageprev = $page - 1;
|
||||
$pagenext = $page + 1;
|
||||
$limit = $conf->liste_limit;
|
||||
if (! $sortfield) $sortfield="l.rowid";
|
||||
if (! $sortorder) $sortorder="DESC";
|
||||
|
||||
$year=$_GET["year"];
|
||||
$filtre=$_GET["filtre"];
|
||||
|
||||
/*
|
||||
* View
|
||||
*/
|
||||
|
||||
$form = new Form($db);
|
||||
$loan = new Loan($db);
|
||||
|
||||
llxHeader();
|
||||
|
||||
$sql = "SELECT cs.rowid as id, cs.fk_type as type, ";
|
||||
$sql.= " cs.amount, cs.date_ech, cs.libelle, cs.paye, cs.periode,";
|
||||
$sql.= " c.libelle as type_lib,";
|
||||
$sql.= " SUM(pc.amount) as alreadypayed";
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX."c_chargesociales as c,";
|
||||
$sql.= " ".MAIN_DB_PREFIX."chargesociales as cs";
|
||||
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."paiementcharge as pc ON pc.fk_charge = cs.rowid";
|
||||
$sql.= " WHERE cs.fk_type = c.id";
|
||||
$sql.= " AND cs.entity = ".$conf->entity;
|
||||
if (GETPOST("search_label")) $sql.=" AND cs.libelle LIKE '%".$db->escape(GETPOST("search_label"))."%'";
|
||||
if ($year > 0)
|
||||
{
|
||||
$sql .= " AND (";
|
||||
// Si period renseignee on l'utilise comme critere de date, sinon on prend date echeance,
|
||||
// ceci afin d'etre compatible avec les cas ou la periode n'etait pas obligatoire
|
||||
$sql .= " (cs.periode IS NOT NULL AND date_format(cs.periode, '%Y') = '".$year."') ";
|
||||
$sql .= "OR (cs.periode IS NULL AND date_format(cs.date_ech, '%Y') = '".$year."')";
|
||||
$sql .= ")";
|
||||
}
|
||||
if ($filtre) {
|
||||
$filtre=str_replace(":","=",$filtre);
|
||||
$sql .= " AND ".$filtre;
|
||||
}
|
||||
if ($typeid) {
|
||||
$sql .= " AND cs.fk_type=".$typeid;
|
||||
}
|
||||
$sql.= " GROUP BY cs.rowid, cs.fk_type, cs.amount, cs.date_ech, cs.libelle, cs.paye, cs.periode, c.libelle";
|
||||
$sql.= $db->order($sortfield,$sortorder);
|
||||
$sql.= $db->plimit($limit+1,$offset);
|
||||
|
||||
|
||||
$resql=$db->query($sql);
|
||||
if ($resql)
|
||||
{
|
||||
$num = $db->num_rows($resql);
|
||||
$i = 0;
|
||||
$var=true;
|
||||
|
||||
$param='';
|
||||
if ($year) $param.='&year='.$year;
|
||||
if ($typeid) $param.='&typeid='.$typeid;
|
||||
|
||||
if ($year)
|
||||
{
|
||||
print_fiche_titre($langs->trans("SocialContributions"),($year?"<a href='index.php?year=".($year-1)."'>".img_previous()."</a> ".$langs->trans("Year")." $year <a href='index.php?year=".($year+1)."'>".img_next()."</a>":""));
|
||||
}
|
||||
else
|
||||
{
|
||||
print_barre_liste($langs->trans("SocialContributions"),$page,$_SERVER["PHP_SELF"],$param,$sortfield,$sortorder,'',$num,$totalnboflines);
|
||||
}
|
||||
|
||||
if (empty($mysoc->country_id) && empty($mysoc->country_code))
|
||||
{
|
||||
print '<div class="error">';
|
||||
$langs->load("errors");
|
||||
$countrynotdefined=$langs->trans("ErrorSetACountryFirst");
|
||||
print $countrynotdefined;
|
||||
print '</div>';
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
print '<form method="GET" action="'.$_SERVER["PHP_SELF"].'">';
|
||||
|
||||
print "<table class=\"noborder\" width=\"100%\">";
|
||||
|
||||
print "<tr class=\"liste_titre\">";
|
||||
print_liste_field_titre($langs->trans("Ref"),$_SERVER["PHP_SELF"],"id","",$param,"",$sortfield,$sortorder);
|
||||
print_liste_field_titre($langs->trans("Label"),$_SERVER["PHP_SELF"],"cs.libelle","",$param,'align="left"',$sortfield,$sortorder);
|
||||
print_liste_field_titre($langs->trans("Type"),$_SERVER["PHP_SELF"],"type","",$param,'align="left"',$sortfield,$sortorder);
|
||||
print_liste_field_titre($langs->trans("PeriodEndDate"),$_SERVER["PHP_SELF"],"periode","",$param,'align="center"',$sortfield,$sortorder);
|
||||
print_liste_field_titre($langs->trans("Amount"),$_SERVER["PHP_SELF"],"cs.amount","",$param,'align="right"',$sortfield,$sortorder);
|
||||
print_liste_field_titre($langs->trans("DateDue"),$_SERVER["PHP_SELF"],"cs.date_ech","",$param,'align="center"',$sortfield,$sortorder);
|
||||
print_liste_field_titre($langs->trans("Status"),$_SERVER["PHP_SELF"],"cs.paye","",$param,'align="right"',$sortfield,$sortorder);
|
||||
print "</tr>\n";
|
||||
|
||||
print '<tr class="liste_titre">';
|
||||
print '<td class="liste_titre"> </td>';
|
||||
print '<td class="liste_titre"><input type="text" class="flat" size="8" name="search_label" value="'.GETPOST("search_label").'"></td>';
|
||||
// Type
|
||||
print '<td class="liste_titre" align="left">';
|
||||
$formsocialcontrib->select_type_socialcontrib($typeid,'typeid',1,16,0);
|
||||
print '</td>';
|
||||
// Period end date
|
||||
print '<td class="liste_titre"> </td>';
|
||||
print '<td class="liste_titre"> </td>';
|
||||
print '<td class="liste_titre"> </td>';
|
||||
print '<td class="liste_titre" align="right">';
|
||||
print '<input type="image" class="liste_titre" src="'.img_picto($langs->trans("Search"),'search.png','','',1).'" name="button_search" value="'.dol_escape_htmltag($langs->trans("Search")).'" title="'.dol_escape_htmltag($langs->trans("Search")).'">';
|
||||
print '</td>';
|
||||
print "</tr>\n";
|
||||
|
||||
while ($i < min($num,$limit))
|
||||
{
|
||||
$obj = $db->fetch_object($resql);
|
||||
|
||||
$var = !$var;
|
||||
print "<tr ".$bc[$var].">";
|
||||
|
||||
// Ref
|
||||
print '<td width="60">';
|
||||
$loan->id=$obj->id;
|
||||
$loan->lib=$obj->id;
|
||||
$loan->ref=$obj->id;
|
||||
print $loan->getNomUrl(1,'20');
|
||||
print '</td>';
|
||||
|
||||
// Label
|
||||
print '<td>'.dol_trunc($obj->libelle,42).'</td>';
|
||||
|
||||
// Type
|
||||
print '<td>'.dol_trunc($obj->type_lib,16).'</td>';
|
||||
|
||||
// Date end period
|
||||
print '<td align="center">';
|
||||
if ($obj->periode)
|
||||
{
|
||||
print '<a href="index.php?year='.strftime("%Y",$db->jdate($obj->periode)).'">'.dol_print_date($db->jdate($obj->periode),'day').'</a>';
|
||||
}
|
||||
else
|
||||
{
|
||||
print ' ';
|
||||
}
|
||||
print '</td>';
|
||||
|
||||
print '<td align="right" width="100">'.price($obj->amount).'</td>';
|
||||
|
||||
// Due date
|
||||
print '<td width="110" align="center">'.dol_print_date($db->jdate($obj->date_ech), 'day').'</td>';
|
||||
|
||||
print '<td align="right" class="nowrap">'.$loan->LibStatut($obj->paye,5,$obj->alreadypayed).'</a></td>';
|
||||
|
||||
print '</tr>';
|
||||
$i++;
|
||||
}
|
||||
|
||||
print '</table>';
|
||||
|
||||
print '</form>';
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
dol_print_error($db);
|
||||
}
|
||||
|
||||
$db->close();
|
||||
|
||||
llxFooter();
|
||||
65
htdocs/compta/loan/info.php
Normal file
65
htdocs/compta/loan/info.php
Normal file
@ -0,0 +1,65 @@
|
||||
<?php
|
||||
/* Copyright (C) 2005-2009 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||
*
|
||||
* 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/compta/sociales/info.php
|
||||
* \ingroup tax
|
||||
* \brief Page with info about social contribution
|
||||
*/
|
||||
|
||||
require '../../main.inc.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/compta/sociales/class/chargesociales.class.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/lib/tax.lib.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
|
||||
|
||||
$langs->load("compta");
|
||||
$langs->load("bills");
|
||||
|
||||
$id=GETPOST('id','int');
|
||||
$action=GETPOST("action");
|
||||
|
||||
// Security check
|
||||
$socid = GETPOST('socid','int');
|
||||
if ($user->societe_id) $socid=$user->societe_id;
|
||||
$result = restrictedArea($user, 'tax', $id, 'chargesociales','charges');
|
||||
|
||||
|
||||
/*
|
||||
* View
|
||||
*/
|
||||
|
||||
$help_url='EN:Module_Taxes_and_social_contributions|FR:Module Taxes et dividendes|ES:Módulo Impuestos y cargas sociales (IVA, impuestos)';
|
||||
llxHeader("",$langs->trans("SocialContribution"),$help_url);
|
||||
|
||||
$chargesociales = new ChargeSociales($db);
|
||||
$chargesociales->fetch($id);
|
||||
$chargesociales->info($id);
|
||||
|
||||
$head = tax_prepare_head($chargesociales);
|
||||
|
||||
dol_fiche_head($head, 'info', $langs->trans("SocialContribution"), 0, 'bill');
|
||||
|
||||
|
||||
print '<table width="100%"><tr><td>';
|
||||
dol_print_object_info($chargesociales);
|
||||
print '</td></tr></table>';
|
||||
|
||||
print '</div>';
|
||||
|
||||
llxFooter();
|
||||
|
||||
$db->close();
|
||||
66
htdocs/core/lib/loan.lib.php
Normal file
66
htdocs/core/lib/loan.lib.php
Normal file
@ -0,0 +1,66 @@
|
||||
<?php
|
||||
/* Copyright (C) 2014 Alexandre Spangaro <alexandre.spangaro@gmail.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/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file htdocs/core/lib/loan.lib.php
|
||||
* \ingroup loan
|
||||
* \brief Library for loan module
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Prepare array with list of tabs
|
||||
*
|
||||
* @param Object $object Object related to tabs
|
||||
* @return array Array of tabs to show
|
||||
*/
|
||||
function loan_prepare_head($object)
|
||||
{
|
||||
global $langs, $conf;
|
||||
|
||||
$h = 0;
|
||||
$head = array();
|
||||
|
||||
$head[$h][0] = DOL_URL_ROOT.'/compta/loan/card.php?id='.$object->id;
|
||||
$head[$h][1] = $langs->trans('Card');
|
||||
$head[$h][2] = 'card';
|
||||
$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); to remove a tab
|
||||
complete_head_from_modules($conf,$langs,$object,$head,$h,'loan');
|
||||
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
|
||||
$upload_dir = $conf->loan->dir_output . "/" . dol_sanitizeFileName($object->ref);
|
||||
$nbFiles = count(dol_dir_list($upload_dir,'files',0,'','(\.meta|_preview\.png)$'));
|
||||
$head[$h][0] = DOL_URL_ROOT.'/compta/loan/document.php?id='.$object->id;
|
||||
$head[$h][1] = $langs->trans("Documents");
|
||||
if($nbFiles > 0) $head[$h][1].= ' ('.$nbFiles.')';
|
||||
$head[$h][2] = 'documents';
|
||||
$h++;
|
||||
|
||||
$head[$h][0] = DOL_URL_ROOT.'/compta/loan/info.php?id='.$object->id;
|
||||
$head[$h][1] = $langs->trans("Info");
|
||||
$head[$h][2] = 'info';
|
||||
$h++;
|
||||
|
||||
complete_head_from_modules($conf,$langs,$object,$head,$h,'loan','remove');
|
||||
|
||||
return $head;
|
||||
}
|
||||
@ -134,9 +134,9 @@ function print_eldy_menu($db,$atarget,$type_user,&$tabMenu,&$menu,$noout=0)
|
||||
}
|
||||
|
||||
// Financial
|
||||
$tmpentry=array('enabled'=>(! empty($conf->comptabilite->enabled) || ! empty($conf->accounting->enabled) || ! empty($conf->facture->enabled) || ! empty($conf->don->enabled) || ! empty($conf->tax->enabled) || ! empty($conf->salaries->enabled)),
|
||||
'perms'=>(! empty($user->rights->compta->resultat->lire) || ! empty($user->rights->accounting->plancompte->lire) || ! empty($user->rights->facture->lire) || ! empty($user->rights->don->lire) || ! empty($user->rights->tax->charges->lire) || ! empty($user->rights->salaries->read)),
|
||||
'module'=>'comptabilite|accounting|facture|don|tax|salaries');
|
||||
$tmpentry=array('enabled'=>(! empty($conf->comptabilite->enabled) || ! empty($conf->accounting->enabled) || ! empty($conf->facture->enabled) || ! empty($conf->don->enabled) || ! empty($conf->tax->enabled) || ! empty($conf->salaries->enabled) || ! empty($conf->loan->enabled)),
|
||||
'perms'=>(! empty($user->rights->compta->resultat->lire) || ! empty($user->rights->accounting->plancompte->lire) || ! empty($user->rights->facture->lire) || ! empty($user->rights->don->lire) || ! empty($user->rights->tax->charges->lire) || ! empty($user->rights->salaries->read) || ! empty($user->rights->loan->read)),
|
||||
'module'=>'comptabilite|accounting|facture|don|tax|salaries|loan');
|
||||
$showmode=dol_eldy_showmenu($type_user, $tmpentry, $listofmodulesforexternal);
|
||||
if ($showmode)
|
||||
{
|
||||
@ -802,11 +802,11 @@ function print_left_eldy_menu($db,$menu_array_before,$menu_array_after,&$tabMenu
|
||||
}
|
||||
|
||||
// Taxes and social contributions
|
||||
if (! empty($conf->tax->enabled) || ! empty($conf->salaries->enabled))
|
||||
if (! empty($conf->tax->enabled) || ! empty($conf->salaries->enabled) || ! empty($conf->loan->enabled))
|
||||
{
|
||||
global $mysoc;
|
||||
|
||||
$permtoshowmenu=((! empty($conf->tax->enabled) && $user->rights->tax->charges->lire) || (! empty($conf->salaries->enabled) && $user->rights->salaries->read));
|
||||
$permtoshowmenu=((! empty($conf->tax->enabled) && $user->rights->tax->charges->lire) || (! empty($conf->salaries->enabled) && $user->rights->salaries->read) || (! empty($conf->loan->enabled) && $user->rights->loan->read));
|
||||
$newmenu->add("/compta/charges/index.php?leftmenu=tax&mainmenu=accountancy",$langs->trans("MenuSpecialExpenses"), 0, $permtoshowmenu, '', $mainmenu, 'tax');
|
||||
|
||||
// Salaries
|
||||
@ -817,6 +817,15 @@ function print_left_eldy_menu($db,$menu_array_before,$menu_array_after,&$tabMenu
|
||||
if (empty($leftmenu) || preg_match('/^tax_salary/i',$leftmenu)) $newmenu->add("/compta/salaries/fiche.php?leftmenu=tax_salary&action=create",$langs->trans("NewPayment"),2,$user->rights->salaries->write);
|
||||
if (empty($leftmenu) || preg_match('/^tax_salary/i',$leftmenu)) $newmenu->add("/compta/salaries/index.php?leftmenu=tax_salary",$langs->trans("Payments"),2,$user->rights->salaries->read);
|
||||
}
|
||||
|
||||
// Loan
|
||||
if (! empty($conf->loan->enabled))
|
||||
{
|
||||
$langs->load("loan");
|
||||
$newmenu->add("/compta/loan/index.php?leftmenu=tax_loan&mainmenu=accountancy",$langs->trans("Loans"),1,$user->rights->loan->read, '', $mainmenu, 'tax_loan');
|
||||
if (empty($leftmenu) || preg_match('/^tax_loan/i',$leftmenu)) $newmenu->add("/compta/loan/card.php?leftmenu=tax_loan&action=create",$langs->trans("NewLoan"),2,$user->rights->loan->write);
|
||||
if (empty($leftmenu) || preg_match('/^tax_loan/i',$leftmenu)) $newmenu->add("/compta/loan/index.php?leftmenu=tax_loan",$langs->trans("Payments"),2,$user->rights->loan->read);
|
||||
}
|
||||
|
||||
// Social contributions
|
||||
if (! empty($conf->tax->enabled))
|
||||
|
||||
173
htdocs/core/modules/modLoan.class.php
Normal file
173
htdocs/core/modules/modLoan.class.php
Normal file
@ -0,0 +1,173 @@
|
||||
<?php
|
||||
/* Copyright (C) 2014 Alexandre Spangaro <alexandre.spangaro@gmail.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/>.
|
||||
* or see http://www.gnu.org/
|
||||
*/
|
||||
|
||||
/**
|
||||
* \defgroup tax Module Loans
|
||||
* \brief Module to include loans management
|
||||
* \file htdocs/core/modules/modLoan.class.php
|
||||
* \ingroup loan
|
||||
* \brief File to activate module loan
|
||||
*/
|
||||
include_once DOL_DOCUMENT_ROOT .'/core/modules/DolibarrModules.class.php';
|
||||
|
||||
|
||||
/**
|
||||
* Class to manage loan module
|
||||
*/
|
||||
class modLoan extends DolibarrModules
|
||||
{
|
||||
|
||||
/**
|
||||
* Constructor. Define names, constants, directories, boxes, permissions
|
||||
*
|
||||
* @param DoliDB $db Database handler
|
||||
*/
|
||||
function __construct($db)
|
||||
{
|
||||
global $conf;
|
||||
|
||||
$this->db = $db;
|
||||
$this->numero = 520;
|
||||
|
||||
$this->family = "financial";
|
||||
// Module label (no space allowed), used if translation string 'ModuleXXXName' not found (where XXX is value of numeric property 'numero' of module)
|
||||
$this->name = preg_replace('/^mod/i','',get_class($this));
|
||||
// Module description used if translation string 'ModuleXXXDesc' not found (where XXX is value of numeric property 'numero' of module)
|
||||
$this->description = "Loans management";
|
||||
|
||||
// Possible values for version are: 'development', 'experimental', 'dolibarr' or version
|
||||
$this->version = 'development';
|
||||
|
||||
$this->const_name = 'MAIN_MODULE_'.strtoupper($this->name);
|
||||
$this->special = 0;
|
||||
$this->picto='bill';
|
||||
|
||||
// Data directories to create when module is enabled
|
||||
$this->dirs = array("/loan/temp");
|
||||
|
||||
// Config pages
|
||||
$this->config_page_url = array('loan.php');
|
||||
|
||||
// Dependances
|
||||
$this->depends = array();
|
||||
$this->requiredby = array();
|
||||
$this->conflictwith = array();
|
||||
$this->langfiles = array("loan");
|
||||
|
||||
// Constants
|
||||
$this->const = array();
|
||||
$this->const[0] = array(
|
||||
"LOAN_ACCOUNTING_ACCOUNT_CAPITAL",
|
||||
"chaine",
|
||||
"164"
|
||||
);
|
||||
$this->const[1] = array(
|
||||
"LOAN_ACCOUNTING_ACCOUNT_INTEREST",
|
||||
"chaine",
|
||||
"6611"
|
||||
);
|
||||
$this->const[1] = array(
|
||||
"LOAN_ACCOUNTING_ACCOUNT_INSURANCE",
|
||||
"chaine",
|
||||
"6162"
|
||||
);
|
||||
|
||||
// Boxes
|
||||
$this->boxes = array();
|
||||
|
||||
// Permissions
|
||||
$this->rights = array();
|
||||
$this->rights_class = 'loan';
|
||||
$r=0;
|
||||
|
||||
$r++;
|
||||
$this->rights[$r][0] = 520;
|
||||
$this->rights[$r][1] = 'Read loans';
|
||||
$this->rights[$r][2] = 'r';
|
||||
$this->rights[$r][3] = 1;
|
||||
$this->rights[$r][4] = 'read';
|
||||
$this->rights[$r][5] = '';
|
||||
|
||||
$r++;
|
||||
$this->rights[$r][0] = 522;
|
||||
$this->rights[$r][1] = 'Create/modify loans';
|
||||
$this->rights[$r][2] = 'w';
|
||||
$this->rights[$r][3] = 0;
|
||||
$this->rights[$r][4] = 'write';
|
||||
$this->rights[$r][5] = '';
|
||||
|
||||
$r++;
|
||||
$this->rights[$r][0] = 524;
|
||||
$this->rights[$r][1] = 'Delete loans';
|
||||
$this->rights[$r][2] = 'd';
|
||||
$this->rights[$r][3] = 0;
|
||||
$this->rights[$r][4] = 'delete';
|
||||
$this->rights[$r][5] = '';
|
||||
|
||||
$r++;
|
||||
$this->rights[$r][0] = 527;
|
||||
$this->rights[$r][1] = 'Export loans';
|
||||
$this->rights[$r][2] = 'r';
|
||||
$this->rights[$r][3] = 0;
|
||||
$this->rights[$r][4] = 'export';
|
||||
$this->rights[$r][5] = '';
|
||||
|
||||
|
||||
// Exports
|
||||
//--------
|
||||
$r=0;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Function called when module is enabled.
|
||||
* The init function add constants, boxes, permissions and menus (defined in constructor) into Dolibarr database.
|
||||
* It also creates data directories
|
||||
*
|
||||
* @param string $options Options when enabling module ('', 'noboxes')
|
||||
* @return int 1 if OK, 0 if KO
|
||||
*/
|
||||
function init($options='')
|
||||
{
|
||||
global $conf;
|
||||
|
||||
// Clean before activation
|
||||
$this->remove($options);
|
||||
|
||||
$sql = array();
|
||||
|
||||
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='')
|
||||
{
|
||||
$sql = array();
|
||||
|
||||
return $this->_remove($sql,$options);
|
||||
}
|
||||
|
||||
}
|
||||
47
htdocs/install/mysql/tables/llx_loan.sql
Normal file
47
htdocs/install/mysql/tables/llx_loan.sql
Normal file
@ -0,0 +1,47 @@
|
||||
-- ========================================================================
|
||||
-- Copyright (C) 2014 Alexandre Spangaro <alexandre.spangaro@gmail.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_loan
|
||||
(
|
||||
rowid integer AUTO_INCREMENT PRIMARY KEY,
|
||||
entity integer DEFAULT 1 NOT NULL,
|
||||
datec datetime,
|
||||
tms timestamp,
|
||||
|
||||
label varchar(80) NOT NULL,
|
||||
fk_bank integer,
|
||||
|
||||
capital real default 0 NOT NULL,
|
||||
datestart date,
|
||||
dateend date,
|
||||
nbterm real,
|
||||
rate double NOT NULL,
|
||||
|
||||
note text,
|
||||
|
||||
capital_position real default 0, -- If not a new loan, just have the position of capital
|
||||
date_position date,
|
||||
|
||||
accountancy_account_capital varchar(32),
|
||||
accountancy_account_insurance varchar(32),
|
||||
accountancy_account_interest varchar(32),
|
||||
|
||||
fk_user_author integer DEFAULT NULL,
|
||||
fk_user_modif integer DEFAULT NULL,
|
||||
active tinyint DEFAULT 1 NOT NULL
|
||||
)ENGINE=innodb;
|
||||
33
htdocs/install/mysql/tables/llx_payment_loan.sql
Normal file
33
htdocs/install/mysql/tables/llx_payment_loan.sql
Normal file
@ -0,0 +1,33 @@
|
||||
-- ===================================================================
|
||||
-- Copyright (C) 2014 Alexandre Spangaro <alexandre.spangaro@gmail.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_payment_loan
|
||||
(
|
||||
rowid integer AUTO_INCREMENT PRIMARY KEY,
|
||||
fk_loan integer,
|
||||
datec datetime, -- creation date
|
||||
tms timestamp,
|
||||
datep datetime, -- payment date
|
||||
amount real DEFAULT 0,
|
||||
fk_typepayment integer NOT NULL,
|
||||
num_payment varchar(50),
|
||||
note text,
|
||||
fk_bank integer NOT NULL,
|
||||
fk_user_creat integer, -- creation user
|
||||
fk_user_modif integer -- last modification user
|
||||
)ENGINE=innodb;
|
||||
Loading…
Reference in New Issue
Block a user