Skip to content

Commit

Permalink
Upgrade accountancy in 3.8 backported
Browse files Browse the repository at this point in the history
  • Loading branch information
aspangaro committed Apr 19, 2016
1 parent 4a6a116 commit 8902e1b
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 70 deletions.
6 changes: 4 additions & 2 deletions htdocs/accountancy/class/html.formventilation.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,9 @@ function select_bookkeeping_importkey($htmlname = 'importkey', $selectedkey = ''
*/
function select_account($selectid, $htmlname = 'account', $showempty = 0, $event = array(), $select_in = 0, $select_out = 0, $aabase = '') {
global $conf;


require_once DOL_DOCUMENT_ROOT . '/core/lib/accounting.lib.php';

$out = '';

$sql = "SELECT DISTINCT aa.account_number, aa.label, aa.rowid, aa.fk_pcg_version";
Expand All @@ -123,7 +125,7 @@ function select_account($selectid, $htmlname = 'account', $showempty = 0, $event
if ($num) {
while ( $i < $num ) {
$obj = $this->db->fetch_object($resql);
$label = $obj->account_number . ' - ' . $obj->label;
$label = length_accountg($obj->account_number) . ' - ' . $obj->label;
$label = dol_trunc($label, $trunclength);
if ($select_in == 0)
$select_value_in = $obj->rowid;
Expand Down
41 changes: 2 additions & 39 deletions htdocs/core/lib/accounting.lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ function length_accountg($account)
// Clean parameters
$i = strlen($account);

if ($i >= 2) {
if ($i >= 1) {
while ( $i < $g ) {
$account .= '0';

Expand Down Expand Up @@ -139,7 +139,7 @@ function length_accounta($accounta)
// Clean parameters
$i = strlen($accounta);

if ($i >= 2) {
if ($i >= 1) {
while ( $i < $a ) {
$accounta .= '0';

Expand All @@ -154,40 +154,3 @@ function length_accounta($accounta)
return $accounta;
}
}

/**
* Return accounting account with defined length for Sage Export Software
*
* @param string $txt Accounting account
* @param int $len Length
* @param int $end Number of characters
*
* @return string Formated string
*/
function length_exportsage($txt, $len, $end)
{
// $txt = utf8_decode($txt);
// problem with this function, but we need to have the number of letter
if (strlen($txt) == $len) {
$res = $txt;
}

elseif (strlen($txt) > $len) {
$res = substr($txt, 0, $len);
}

else {
if ($end == 1) {
$res = $txt;
} else {
$res = "";
}
for($i = strlen($txt); $i <= ($len - 1); $i ++) {
$res .= " ";
}
if ($end == 0) {
$res .= $txt;
}
}
return $res;
}
103 changes: 74 additions & 29 deletions htdocs/product/card.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,12 @@
require_once DOL_DOCUMENT_ROOT.'/core/class/genericobject.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/product.lib.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/accounting.lib.php';
require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
if (! empty($conf->propal->enabled)) require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php';
if (! empty($conf->facture->enabled)) require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
if (! empty($conf->commande->enabled)) require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
if (! empty($conf->accounting->enabled)) require_once DOL_DOCUMENT_ROOT.'/accountancy/class/html.formventilation.class.php';

$langs->load("products");
$langs->load("other");
Expand Down Expand Up @@ -153,6 +155,7 @@
}
}

/*
if ($action == 'setaccountancy_code_buy') {
$result = $object->setAccountancyCode('buy', GETPOST('accountancy_code_buy'));
Expand All @@ -166,6 +169,7 @@
if ($result < 0) setEventMessage(join(',',$object->errors), 'errors');
$action="";
}
*/

// Add a product or service
if ($action == 'add' && ($user->rights->produit->creer || $user->rights->service->creer))
Expand Down Expand Up @@ -251,8 +255,11 @@
$object->finished = GETPOST('finished');
$object->hidden = GETPOST('hidden')=='yes'?1:0;
$object->fk_unit = GETPOST('units');
$object->accountancy_code_sell = GETPOST('accountancy_code_sell');
$object->accountancy_code_buy = GETPOST('accountancy_code_buy');

$accountancy_code_sell = GETPOST('accountancy_code_sell');
$accountancy_code_buy = GETPOST('accountancy_code_buy');
if ($accountancy_code_sell <= 0) { $object->accountancy_code_sell = ''; } else { $object->accountancy_code_sell = $accountancy_code_sell; }
if ($accountancy_code_buy <= 0) { $object->accountancy_code_buy = ''; } else { $object->accountancy_code_buy = $accountancy_code_buy; }

// MultiPrix
if (! empty($conf->global->PRODUIT_MULTIPRICES))
Expand Down Expand Up @@ -364,8 +371,11 @@
$object->barcode_type_coder = $stdobject->barcode_type_coder;
$object->barcode_type_label = $stdobject->barcode_type_label;

$object->accountancy_code_sell = GETPOST('accountancy_code_sell');
$object->accountancy_code_buy = GETPOST('accountancy_code_buy');
$accountancy_code_sell = GETPOST('accountancy_code_sell');
$accountancy_code_buy = GETPOST('accountancy_code_buy');

if ($accountancy_code_sell <= 0) { $object->accountancy_code_sell = ''; } else { $object->accountancy_code_sell = $accountancy_code_sell; }
if ($accountancy_code_buy <= 0) { $object->accountancy_code_buy = ''; } else { $object->accountancy_code_buy = $accountancy_code_buy; }

// Fill array 'array_options' with data from add form
$ret = $extrafields->setOptionalsFromPost($extralabels,$object);
Expand Down Expand Up @@ -724,7 +734,7 @@

$form = new Form($db);
$formproduct = new FormProduct($db);

if (! empty($conf->accounting->enabled)) $formaccountancy = New FormVentilation($db);

if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action))
{
Expand Down Expand Up @@ -1009,15 +1019,32 @@

print '<table class="border" width="100%">';

// Accountancy_code_sell
print '<tr><td>'.$langs->trans("ProductAccountancySellCode").'</td>';
print '<td><input name="accountancy_code_sell" size="16" value="'.$object->accountancy_code_sell.'">';
print '</td></tr>';
if (! empty($conf->accounting->enabled))
{
// Accountancy_code_sell
print '<tr><td width="20%">'.$langs->trans("ProductAccountancySellCode").'</td>';
print '<td>';
print $formaccountancy->select_account($object->accountancy_code_sell, 'accountancy_code_sell', 1, '', 0, 1);
print '</td></tr>';

// Accountancy_code_buy
print '<tr><td width="20%">'.$langs->trans("ProductAccountancyBuyCode").'</td>';
print '<td><input name="accountancy_code_buy" size="16" value="'.$object->accountancy_code_buy.'">';
print '</td></tr>';
// Accountancy_code_buy
print '<tr><td>'.$langs->trans("ProductAccountancyBuyCode").'</td>';
print '<td>';
print $formaccountancy->select_account($object->accountancy_code_buy, 'accountancy_code_buy', 1, '', 0, 1);
print '</td></tr>';
}
else // For external software
{
// Accountancy_code_sell
print '<tr><td width="20%">'.$langs->trans("ProductAccountancySellCode").'</td>';
print '<td><input name="accountancy_code_sell" size="16" value="'.$object->accountancy_code_sell.'">';
print '</td></tr>';

// Accountancy_code_buy
print '<tr><td>'.$langs->trans("ProductAccountancyBuyCode").'</td>';
print '<td><input name="accountancy_code_buy" size="16" value="'.$object->accountancy_code_buy.'">';
print '</td></tr>';
}

print '</table>';

Expand Down Expand Up @@ -1267,26 +1294,34 @@

print '<br>';

/*if (empty($conf->accounting->enabled) && empty($conf->comptabilite->enabled) && empty($conf->accountingexpert->enabled))
{
// Don't show accounting field when accounting id disabled.
}
else
{*/
print '<table class="border" width="100%">';
print '<table class="border" width="100%">';
if (! empty($conf->accounting->enabled))
{
// Accountancy_code_sell
print '<tr><td width="20%">'.$langs->trans("ProductAccountancySellCode").'</td>';
print '<td>';
print $formaccountancy->select_account($object->accountancy_code_sell, 'accountancy_code_sell', 1, '', 1, 1);
print '</td></tr>';

// Accountancy_code_buy
print '<tr><td>'.$langs->trans("ProductAccountancyBuyCode").'</td>';
print '<td>';
print $formaccountancy->select_account($object->accountancy_code_buy, 'accountancy_code_buy', 1, '', 1, 1);
print '</td></tr>';
}
else // For external software
{
// Accountancy_code_sell
print '<tr><td width="20%">'.$langs->trans("ProductAccountancySellCode").'</td>';
print '<td><input name="accountancy_code_sell" size="16" value="'.$object->accountancy_code_sell.'">';
print '</td></tr>';

// Accountancy_code_buy
print '<tr><td width="20%">'.$langs->trans("ProductAccountancyBuyCode").'</td>';
// Accountancy_code_buy
print '<tr><td>'.$langs->trans("ProductAccountancyBuyCode").'</td>';
print '<td><input name="accountancy_code_buy" size="16" value="'.$object->accountancy_code_buy.'">';
print '</td></tr>';

print '</table>';
//}
}
print '</table>';

dol_fiche_end();

Expand Down Expand Up @@ -1405,13 +1440,23 @@
}

// Accountancy sell code
print '<tr><td>'.$form->editfieldkey("ProductAccountancySellCode",'accountancy_code_sell',$object->accountancy_code_sell,$object,$user->rights->produit->creer||$user->rights->service->creer,'string').'</td><td colspan="2">';
print $form->editfieldval("ProductAccountancySellCode",'accountancy_code_sell',$object->accountancy_code_sell,$object,$user->rights->produit->creer||$user->rights->service->creer,'string');
print '<tr><td class="nowrap">';
print '<table width="100%" class="nobordernopadding"><tr><td class="nowrap">';
print $langs->trans("ProductAccountancySellCode");
print '</td>';
print '</tr></table>';
print '</td><td colspan="2">';
print length_accountg($object->accountancy_code_sell);
print '</td></tr>';

// Accountancy buy code
print '<tr><td>'.$form->editfieldkey("ProductAccountancyBuyCode",'accountancy_code_buy',$object->accountancy_code_buy,$object,$user->rights->produit->creer||$user->rights->service->creer,'string').'</td><td colspan="2">';
print $form->editfieldval("ProductAccountancyBuyCode",'accountancy_code_buy',$object->accountancy_code_buy,$object,$user->rights->produit->creer||$user->rights->service->creer,'string');
print '<tr><td class="nowrap">';
print '<table width="100%" class="nobordernopadding"><tr><td class="nowrap">';
print $langs->trans("ProductAccountancyBuyCode");
print '</td>';
print '</tr></table>';
print '</td><td colspan="2">';
print length_accountg($object->accountancy_code_buy);
print '</td></tr>';

// Status (to sell)
Expand Down

0 comments on commit 8902e1b

Please sign in to comment.