Skip to content

Commit

Permalink
Merge branch 'develop' of https://github.com/Dolibarr/dolibarr into d…
Browse files Browse the repository at this point in the history
…evelop-api
  • Loading branch information
Neil Orley committed Oct 27, 2017
2 parents dcc5adf + e31223d commit fbabacf
Show file tree
Hide file tree
Showing 81 changed files with 26,388 additions and 318 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Expand Up @@ -79,7 +79,7 @@ matrix:
notifications:
email:
on_success: never # [always|never|change] default: change
on_failure: change # [always|never|change] default: always
on_failure: never # [always|never|change] default: always
irc:
channels:
- "chat.freenode.net#dolibarr"
Expand Down
2 changes: 1 addition & 1 deletion COPYRIGHT
Expand Up @@ -36,7 +36,7 @@ Stripe 4.7.0 MIT licence Yes
JS libraries:
jQuery 3.1.1 MIT License Yes JS library
jQuery UI 1.12.1 GPL and MIT License Yes JS library plugin UI
jQuery select2 4.0.4 GPL and Apache License Yes JS library plugin for sexier multiselect
jQuery select2 4.0.5 GPL and Apache License Yes JS library plugin for sexier multiselect
jQuery blockUI 2.70.0 GPL and MIT License Yes JS library plugin blockUI (to use ajax popups)
jQuery Colorpicker 1.1 MIT License Yes JS library for color picker for a defined list of colors
jQuery Flot 0.8.3 MIT License Yes JS library to build graph
Expand Down
71 changes: 60 additions & 11 deletions htdocs/blockedlog/class/blockedlog.class.php
Expand Up @@ -96,7 +96,8 @@ public function __construct(DoliDB $db)
/**
* try to retrieve logged object link
*/
public function getObjectLink() {
public function getObjectLink()
{
global $langs;

if($this->element === 'facture') {
Expand All @@ -110,6 +111,17 @@ public function getObjectLink() {
$this->error++;
}
}
if($this->element === 'invoice_supplier') {
require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';

$object = new FactureFournisseur($this->db);
if($object->fetch($this->fk_object)>0) {
return $object->getNomUrl(1);
}
else{
$this->error++;
}
}
else if($this->element === 'payment') {
require_once DOL_DOCUMENT_ROOT.'/compta/paiement/class/paiement.class.php';

Expand All @@ -121,6 +133,17 @@ public function getObjectLink() {
$this->error++;
}
}
else if($this->element === 'payment_supplier') {
require_once DOL_DOCUMENT_ROOT.'/fourn/class/paiementfourn.class.php';

$object = new PaiementFourn($this->db);
if($object->fetch($this->fk_object)>0) {
return $object->getNomUrl(1);
}
else{
$this->error++;
}
}

return $langs->trans('ImpossibleToReloadObject', $this->element, $this->fk_object);

Expand All @@ -129,7 +152,8 @@ public function getObjectLink() {
/**
* try to retrieve user author
*/
public function getUser() {
public function getUser()
{
global $langs, $cachedUser;

if(empty($cachedUser))$cachedUser=array();
Expand All @@ -149,14 +173,14 @@ public function getUser() {
}

/**
* populate log by object
* Populate properties of log from object data
*
* @param payment|facture $object object to store
* @param Object $object object to store
*/
public function setObjectData(&$object) {

public function setObjectData(&$object)
{
// Set date
if ($object->element=='payment')
if($object->element == 'payment' || $object->element == 'payment_supplier')
{
$this->date_object = $object->datepaye;
}
Expand All @@ -174,7 +198,7 @@ public function setObjectData(&$object) {

$this->object_data=new stdClass();

if ($this->element === 'facture')
if ($this->element == 'facture')
{
if(empty($object->thirdparty))$object->fetch_thirdparty();
$this->object_data->thirdparty = new stdClass();
Expand All @@ -190,15 +214,31 @@ public function setObjectData(&$object) {
$this->object_data->total_localtax2= (double) $object->total_localtax2;
$this->object_data->note_public = (double) $object->note_public;
}
elseif($this->element === 'payment')
if($this->element == 'invoice_supplier') {
if(empty($object->thirdparty))$object->fetch_thirdparty();
$this->object_data->thirdparty = new stdClass();

foreach($object->thirdparty as $key=>$value) {
if(!is_object($value)) $this->object_data->thirdparty->{$key} = $value;
}

$this->object_data->total_ht = (double) $object->total_ht;
$this->object_data->total_tva = (double) $object->total_tva;
$this->object_data->total_ttc = (double) $object->total_ttc;
$this->object_data->total_localtax1= (double) $object->total_localtax1;
$this->object_data->total_localtax2= (double) $object->total_localtax2;
$this->object_data->note_public = (double) $object->note_public;
$this->object_data->note_private= (double) $object->note_private;

}
elseif ($this->element == 'payment'|| $object->element == 'payment_supplier')
{
$this->object_data->amounts = $object->amounts;
}
elseif($this->element === 'payment_salary')
elseif($this->element == 'payment_salary')
{
$this->object_data->amounts = array($object->amount);
}

}

/**
Expand Down Expand Up @@ -520,6 +560,15 @@ private function getCurrentValue() {
$this->amounts = (double) $obj->amount;
}
}
if($this->element === 'payment_supplier') {
$sql="SELECT amount FROM ".MAIN_DB_PREFIX."paiementfourn WHERE rowid=".$this->fk_object;

$res = $this->db->query($sql);

if($res && $obj = $this->db->fetch_object($res)) {
$this->amounts = (double) $obj->amount;
}
}
elseif($this->element === 'facture') {
$sql="SELECT total_ttc FROM ".MAIN_DB_PREFIX."facture WHERE rowid=".$this->fk_object;

Expand Down
2 changes: 1 addition & 1 deletion htdocs/collab/index.php
Expand Up @@ -155,7 +155,7 @@

$help_url='';

llxHeader('', $langs->trans("WebsiteSetup"), $help_url, '', 0, '', '', '', '', '<!-- Begin div class="fiche" -->'."\n".'<div class="fichebutwithotherclass">');
llxHeader('', $langs->trans("WebsiteSetup"), $help_url, '', 0, '', '', '', '', '', '<!-- Begin div class="fiche" -->'."\n".'<div class="fichebutwithotherclass">');

print "\n".'<form action="'.$_SERVER["PHP_SELF"].'" method="POST"><div>';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
Expand Down
2 changes: 1 addition & 1 deletion htdocs/comm/action/class/actioncomm.class.php
Expand Up @@ -928,7 +928,7 @@ function load_board($user, $load_state_board=0)
$sql.= ")";
if (! $user->rights->societe->client->voir && ! $user->societe_id) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON a.fk_soc = sc.fk_soc";
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON a.fk_soc = s.rowid";
$sql.= " WHERE 1";
$sql.= " WHERE 1 = 1";
if(empty($load_state_board)) $sql.= " AND a.percent >= 0 AND a.percent < 100";
$sql.= " AND a.entity IN (".getEntity('agenda').")";
if (! $user->rights->societe->client->voir && ! $user->societe_id) $sql.= " AND (a.fk_soc IS NULL OR sc.fk_user = " .$user->id . ")";
Expand Down
2 changes: 1 addition & 1 deletion htdocs/comm/propal/card.php
Expand Up @@ -2195,7 +2195,7 @@
// Show object lines
$result = $object->getLinesArray();

print ' <form name="addproduct" id="addproduct" action="' . $_SERVER["PHP_SELF"] . '?id=' . $object->id . (($action != 'editline') ? '#add' : '#line_' . GETPOST('lineid')) . '" method="POST">
print ' <form name="addproduct" id="addproduct" action="' . $_SERVER["PHP_SELF"] . '?id=' . $object->id . (($action != 'editline') ? '#addline' : '#line_' . GETPOST('lineid')) . '" method="POST">
<input type="hidden" name="token" value="' . $_SESSION ['newtoken'] . '">
<input type="hidden" name="action" value="' . (($action != 'editline') ? 'addline' : 'updateligne') . '">
<input type="hidden" name="mode" value="">
Expand Down
2 changes: 1 addition & 1 deletion htdocs/commande/card.php
Expand Up @@ -2388,7 +2388,7 @@
*/
$result = $object->getLinesArray();

print ' <form name="addproduct" id="addproduct" action="' . $_SERVER["PHP_SELF"] . '?id=' . $object->id . (($action != 'editline') ? '#add' : '#line_' . GETPOST('lineid')) . '" method="POST">
print ' <form name="addproduct" id="addproduct" action="' . $_SERVER["PHP_SELF"] . '?id=' . $object->id . (($action != 'editline') ? '#addline' : '#line_' . GETPOST('lineid')) . '" method="POST">
<input type="hidden" name="token" value="' . $_SESSION ['newtoken'] . '">
<input type="hidden" name="action" value="' . (($action != 'editline') ? 'addline' : 'updateline') . '">
<input type="hidden" name="mode" value="">
Expand Down
1 change: 1 addition & 0 deletions htdocs/commande/class/commande.class.php
Expand Up @@ -610,6 +610,7 @@ function cloture($user, $notrigger=0)
return -1;
}
}
return 0;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion htdocs/compta/facture/card.php
Expand Up @@ -4078,7 +4078,7 @@
}
}

print ' <form name="addproduct" id="addproduct" action="' . $_SERVER["PHP_SELF"] . '?id=' . $object->id . (($action != 'editline') ? '#add' : '#line_' . GETPOST('lineid')) . '" method="POST">
print ' <form name="addproduct" id="addproduct" action="' . $_SERVER["PHP_SELF"] . '?id=' . $object->id . (($action != 'editline') ? '#addline' : '#line_' . GETPOST('lineid')) . '" method="POST">
<input type="hidden" name="token" value="' . $_SESSION ['newtoken'] . '">
<input type="hidden" name="action" value="' . (($action != 'editline') ? 'addline' : 'updateligne') . '">
<input type="hidden" name="mode" value="">
Expand Down
90 changes: 12 additions & 78 deletions htdocs/compta/facture/class/api_invoices.class.php
Expand Up @@ -653,28 +653,28 @@ function settopaid($id, $close_code='', $close_note='')


/**
* Insert a discount in a specific invoice
* Add a discount line into an invoice (as an invoice line) using an existing absolute discount (Consume the discount)
*
* @param int $id Id of invoice
* @param int $discountId Id of discount
* @param int $discountid Id of discount
*
* @url POST {id}/adddiscount/{discountId}
* @url POST {id}/usediscount/{discountid}
*
* @return int
* @throws 400
* @throws 401
* @throws 404
* @throws 405
*/
function addDiscount($id, $discountId) {
function useDiscount($id, $discountid) {

if(! DolibarrApiAccess::$user->rights->facture->creer) {
throw new RestException(401);
}
if(empty($id)) {
throw new RestException(400, 'Invoice ID is mandatory');
}
if(empty($discountId)) {
if(empty($discountid)) {
throw new RestException(400, 'Discount ID is mandatory');
}

Expand All @@ -687,7 +687,7 @@ function addDiscount($id, $discountId) {
throw new RestException(404, 'Invoice not found');
}

$result = $this->invoice->insert_discount($discountId);
$result = $this->invoice->insert_discount($discountid);
if( $result < 0) {
throw new RestException(405, $this->invoice->error);
}
Expand All @@ -696,20 +696,20 @@ function addDiscount($id, $discountId) {
}

/**
* Deduct an available credit to an existing invoice
* Add an available credit note discount to payments of an existing invoice (Consume the credit note)
*
* @param int $id Id of invoice
* @param int $creditId Id of the credit to deduct
* @param int $discountid Id of a discount coming from a credit note
*
* @url POST {id}/deductcredit/{creditId}
* @url POST {id}/usecreditnote/{creditnoteid}
*
* @return int
* @throws 400
* @throws 401
* @throws 404
* @throws 405
*/
function deductCredit($id, $creditId) {
function useCreditNote($id, $discountid) {

require_once DOL_DOCUMENT_ROOT . '/core/class/discount.class.php';

Expand All @@ -727,7 +727,7 @@ function deductCredit($id, $creditId) {
throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
}
$discount = new DiscountAbsolute($this->db);
$result = $discount->fetch($creditId);
$result = $discount->fetch($discountid);
if( ! $result ) {
throw new RestException(404, 'Credit not found');
}
Expand All @@ -741,7 +741,7 @@ function deductCredit($id, $creditId) {
}

/**
* Get a payment list of a given invoice
* Get list of payments of a given invoice
*
* @param int $id Id of invoice
*
Expand Down Expand Up @@ -779,72 +779,6 @@ function getPayments($id) {
return $result;
}

/**
* Get a list of available assets (down-payments, avoirs)
*
* @param int $id Id of the invoice
*
* @url GET {id}/getavailableassets
*
* @return array
* @throws 400
* @throws 401
* @throws 404
* @throws 405
*/
function getavailableassets($id) {

if(! DolibarrApiAccess::$user->rights->facture->lire) {
throw new RestException(401);
}
if(empty($id)) {
throw new RestException(400, 'Invoice ID is mandatory');
}

if( ! DolibarrApi::_checkAccessToResource('facture',$id)) {
throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
}

$result = $this->invoice->fetch($id);
if( ! $result ) {
throw new RestException(404, 'Invoice not found');
}

$result = $this->invoice->list_qualified_avoir_invoices($this->invoice->socid);
if( $result < 0) {
throw new RestException(405, $this->invoice->error);
}

$return = array();
foreach ($result as $invoiceID=>$line) {

if($invoiceID == $id) { // ignore current invoice
continue;
}

$result = $this->invoice->fetch($invoiceID);
if( ! $result ) {
throw new RestException(404, 'Invoice '.$invoiceID.' not found');
}

$result = $this->invoice->getListOfPayments();
if( $result < 0) {
throw new RestException(405, $this->invoice->error);
}

if(count($result) == 0) { // ignore unpaid invoices
continue;
}

// format results
$line["id"] = $invoiceID;
$line["payments"] = $result;
$return[] = $line;
}

return $return;
}

/**
* Clean sensible object datas
*
Expand Down

0 comments on commit fbabacf

Please sign in to comment.