repo stringlengths 6 63 | path stringlengths 5 140 | func_name stringlengths 3 151 | original_string stringlengths 84 13k | language stringclasses 1
value | code stringlengths 84 13k | code_tokens list | docstring stringlengths 3 47.2k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 91 247 | partition stringclasses 1
value |
|---|---|---|---|---|---|---|---|---|---|---|---|
SIELOnline/libAcumulus | src/WooCommerce/Shop/InvoiceStatusOverviewForm.php | InvoiceStatusOverviewForm.getDeletedFields | private function getDeletedFields(Source $source)
{
$fields = array();
$fields += array(
'undelete' => array(
'type' => 'button',
'value' => $this->t('undelete'),
'ajax' => array(
'service' => 'entry_deletestatus_set',
'parent_type' => $this->source->getType(),
'parent_source' => $this->source->getId(),
'type' => $source->getType(),
'source' => $source->getId(),
'value' => API::Entry_Delete,
),
),
'send' => array(
'type' => 'button',
'value' => $this->t('send_again'),
'ajax' => array(
'service' => 'invoice_add',
'parent_type' => $this->source->getType(),
'parent_source' => $this->source->getId(),
'type' => $source->getType(),
'source' => $source->getId(),
'value' => 1,
),
),
);
return $fields;
} | php | private function getDeletedFields(Source $source)
{
$fields = array();
$fields += array(
'undelete' => array(
'type' => 'button',
'value' => $this->t('undelete'),
'ajax' => array(
'service' => 'entry_deletestatus_set',
'parent_type' => $this->source->getType(),
'parent_source' => $this->source->getId(),
'type' => $source->getType(),
'source' => $source->getId(),
'value' => API::Entry_Delete,
),
),
'send' => array(
'type' => 'button',
'value' => $this->t('send_again'),
'ajax' => array(
'service' => 'invoice_add',
'parent_type' => $this->source->getType(),
'parent_source' => $this->source->getId(),
'type' => $source->getType(),
'source' => $source->getId(),
'value' => 1,
),
),
);
return $fields;
} | [
"private",
"function",
"getDeletedFields",
"(",
"Source",
"$",
"source",
")",
"{",
"$",
"fields",
"=",
"array",
"(",
")",
";",
"$",
"fields",
"+=",
"array",
"(",
"'undelete'",
"=>",
"array",
"(",
"'type'",
"=>",
"'button'",
",",
"'value'",
"=>",
"$",
"... | Returns additional form fields to show when the invoice has been sent but
subsequently has been deleted in Acumulus.
@param \Siel\Acumulus\Invoice\Source $source
The Source for which the invoice has been deleted.
@return array[]
Array of form fields. | [
"Returns",
"additional",
"form",
"fields",
"to",
"show",
"when",
"the",
"invoice",
"has",
"been",
"sent",
"but",
"subsequently",
"has",
"been",
"deleted",
"in",
"Acumulus",
"."
] | 82f8d6c9c4929c41948c97d6cfdfac3f27c37255 | https://github.com/SIELOnline/libAcumulus/blob/82f8d6c9c4929c41948c97d6cfdfac3f27c37255/src/WooCommerce/Shop/InvoiceStatusOverviewForm.php#L671-L701 | train |
SIELOnline/libAcumulus | src/WooCommerce/Shop/InvoiceStatusOverviewForm.php | InvoiceStatusOverviewForm.getEntryFields | private function getEntryFields(Source $source, BaseAcumulusEntry $localEntryInfo, array $entry)
{
/* keys in $entry array:
* - entryid
* * entrydate: yy-mm-dd
* - entrytype
* - entrydescription
* - entrynote
* - fiscaltype
* * vatreversecharge: 0 or 1
* * foreigneu: 0 or 1
* * foreignnoneu: 0 or 1
* * marginscheme: 0 or 1
* * foreignvat: 0 or 1
* - contactid
* - accountnumber
* - costcenterid
* - costtypeid
* * invoicenumber
* - invoicenote
* - descriptiontext
* - invoicelayoutid
* - totalvalueexclvat
* - totalvalue
* - paymenttermdays
* * paymentdate: yy-mm-dd
* * paymentstatus: 1 or 2
* * deleted: timestamp
*/
$fields = $this->getVatTypeField($entry)
+ $this->getAmountFields($source, $entry)
+ $this->getPaymentStatusFields($source, $entry)
+ $this->getLinksField($localEntryInfo->getToken());
return $fields;
} | php | private function getEntryFields(Source $source, BaseAcumulusEntry $localEntryInfo, array $entry)
{
/* keys in $entry array:
* - entryid
* * entrydate: yy-mm-dd
* - entrytype
* - entrydescription
* - entrynote
* - fiscaltype
* * vatreversecharge: 0 or 1
* * foreigneu: 0 or 1
* * foreignnoneu: 0 or 1
* * marginscheme: 0 or 1
* * foreignvat: 0 or 1
* - contactid
* - accountnumber
* - costcenterid
* - costtypeid
* * invoicenumber
* - invoicenote
* - descriptiontext
* - invoicelayoutid
* - totalvalueexclvat
* - totalvalue
* - paymenttermdays
* * paymentdate: yy-mm-dd
* * paymentstatus: 1 or 2
* * deleted: timestamp
*/
$fields = $this->getVatTypeField($entry)
+ $this->getAmountFields($source, $entry)
+ $this->getPaymentStatusFields($source, $entry)
+ $this->getLinksField($localEntryInfo->getToken());
return $fields;
} | [
"private",
"function",
"getEntryFields",
"(",
"Source",
"$",
"source",
",",
"BaseAcumulusEntry",
"$",
"localEntryInfo",
",",
"array",
"$",
"entry",
")",
"{",
"/* keys in $entry array:\n * - entryid\n * * entrydate: yy-mm-dd\n * - entrytype\n * ... | Returns additional form fields to show when the invoice is still there.
@param \Siel\Acumulus\Invoice\Source $source
@param \Siel\Acumulus\Shop\AcumulusEntry $localEntryInfo
@param array $entry
@return array[]
Array of form fields. | [
"Returns",
"additional",
"form",
"fields",
"to",
"show",
"when",
"the",
"invoice",
"is",
"still",
"there",
"."
] | 82f8d6c9c4929c41948c97d6cfdfac3f27c37255 | https://github.com/SIELOnline/libAcumulus/blob/82f8d6c9c4929c41948c97d6cfdfac3f27c37255/src/WooCommerce/Shop/InvoiceStatusOverviewForm.php#L713-L748 | train |
SIELOnline/libAcumulus | src/WooCommerce/Shop/InvoiceStatusOverviewForm.php | InvoiceStatusOverviewForm.getVatTypeField | private function getVatTypeField(array $entry)
{
if (!empty($entry['vatreversecharge'])) {
if (!empty($entry['foreigneu'])) {
$vatType = API::VatType_EuReversed;
} else {
$vatType = API::VatType_NationalReversed;
}
} elseif (!empty($entry['marginscheme'])) {
$vatType = API::VatType_MarginScheme;
} elseif (!empty($entry['foreignvat'])) {
$vatType = API::VatType_ForeignVat;
} elseif (!empty($entry['foreignnoneu'])) {
$vatType = API::VatType_RestOfWorld;
} else {
$vatType = API::VatType_National;
}
return array(
'vat_type' => array(
'type' => 'markup',
'label' => $this->t('vat_type'),
'value' => $this->t('vat_type_' . $vatType),
),
);
} | php | private function getVatTypeField(array $entry)
{
if (!empty($entry['vatreversecharge'])) {
if (!empty($entry['foreigneu'])) {
$vatType = API::VatType_EuReversed;
} else {
$vatType = API::VatType_NationalReversed;
}
} elseif (!empty($entry['marginscheme'])) {
$vatType = API::VatType_MarginScheme;
} elseif (!empty($entry['foreignvat'])) {
$vatType = API::VatType_ForeignVat;
} elseif (!empty($entry['foreignnoneu'])) {
$vatType = API::VatType_RestOfWorld;
} else {
$vatType = API::VatType_National;
}
return array(
'vat_type' => array(
'type' => 'markup',
'label' => $this->t('vat_type'),
'value' => $this->t('vat_type_' . $vatType),
),
);
} | [
"private",
"function",
"getVatTypeField",
"(",
"array",
"$",
"entry",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"entry",
"[",
"'vatreversecharge'",
"]",
")",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"entry",
"[",
"'foreigneu'",
"]",
")",
")",
... | Returns the vat type field.
@param array $entry
@return array
The vattype field. | [
"Returns",
"the",
"vat",
"type",
"field",
"."
] | 82f8d6c9c4929c41948c97d6cfdfac3f27c37255 | https://github.com/SIELOnline/libAcumulus/blob/82f8d6c9c4929c41948c97d6cfdfac3f27c37255/src/WooCommerce/Shop/InvoiceStatusOverviewForm.php#L758-L782 | train |
SIELOnline/libAcumulus | src/WooCommerce/Shop/InvoiceStatusOverviewForm.php | InvoiceStatusOverviewForm.getAmountFields | private function getAmountFields(Source $source, array $entry)
{
$fields = array();
if (!empty($entry['totalvalue']) && !empty($entry['totalvalueexclvat'])) {
// Get Acumulus amounts.
$amountExAcumulus = $entry['totalvalueexclvat'];
$amountIncAcumulus = $entry['totalvalue'];
$amountVatAcumulus = $amountIncAcumulus - $amountExAcumulus;
// Get local amounts.
$localTotals = $source->getTotals();
// Compare.
$amountExStatus = $this->getAmountStatus($amountExAcumulus, $localTotals[Meta::InvoiceAmount]);
$amountIncStatus = $this->getAmountStatus($amountIncAcumulus, $localTotals[Meta::InvoiceAmountInc]);
$amountVatStatus = $this->getAmountStatus($amountVatAcumulus, $localTotals[Meta::InvoiceVatAmount]);
$amountEx = $this->getFormattedAmount($amountExAcumulus, $amountExStatus);
$amountInc = $this->getFormattedAmount($amountIncAcumulus, $amountIncStatus);
$amountVat = $this->getFormattedAmount($amountVatAcumulus, $amountVatStatus);
$fields['invoice_amount'] = array(
'type' => 'markup',
'label' => $this->t('invoice_amount'),
'value' => sprintf('<div class="acumulus-amount">%1$s%2$s %4$s%3$s</div>', $amountEx, $amountVat, $amountInc, $this->t('vat')),
);
}
return $fields;
} | php | private function getAmountFields(Source $source, array $entry)
{
$fields = array();
if (!empty($entry['totalvalue']) && !empty($entry['totalvalueexclvat'])) {
// Get Acumulus amounts.
$amountExAcumulus = $entry['totalvalueexclvat'];
$amountIncAcumulus = $entry['totalvalue'];
$amountVatAcumulus = $amountIncAcumulus - $amountExAcumulus;
// Get local amounts.
$localTotals = $source->getTotals();
// Compare.
$amountExStatus = $this->getAmountStatus($amountExAcumulus, $localTotals[Meta::InvoiceAmount]);
$amountIncStatus = $this->getAmountStatus($amountIncAcumulus, $localTotals[Meta::InvoiceAmountInc]);
$amountVatStatus = $this->getAmountStatus($amountVatAcumulus, $localTotals[Meta::InvoiceVatAmount]);
$amountEx = $this->getFormattedAmount($amountExAcumulus, $amountExStatus);
$amountInc = $this->getFormattedAmount($amountIncAcumulus, $amountIncStatus);
$amountVat = $this->getFormattedAmount($amountVatAcumulus, $amountVatStatus);
$fields['invoice_amount'] = array(
'type' => 'markup',
'label' => $this->t('invoice_amount'),
'value' => sprintf('<div class="acumulus-amount">%1$s%2$s %4$s%3$s</div>', $amountEx, $amountVat, $amountInc, $this->t('vat')),
);
}
return $fields;
} | [
"private",
"function",
"getAmountFields",
"(",
"Source",
"$",
"source",
",",
"array",
"$",
"entry",
")",
"{",
"$",
"fields",
"=",
"array",
"(",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"entry",
"[",
"'totalvalue'",
"]",
")",
"&&",
"!",
"empty",
... | Returns the amounts of this invoice.
@param \Siel\Acumulus\Invoice\Source $source
@param array $entry
@return array[]
Array with form fields with the payment status and date (if paid) of
the invoice. | [
"Returns",
"the",
"amounts",
"of",
"this",
"invoice",
"."
] | 82f8d6c9c4929c41948c97d6cfdfac3f27c37255 | https://github.com/SIELOnline/libAcumulus/blob/82f8d6c9c4929c41948c97d6cfdfac3f27c37255/src/WooCommerce/Shop/InvoiceStatusOverviewForm.php#L881-L909 | train |
SIELOnline/libAcumulus | src/WooCommerce/Shop/InvoiceStatusOverviewForm.php | InvoiceStatusOverviewForm.getAmountStatus | private function getAmountStatus($amount, $amountLocal)
{
if (Number::floatsAreEqual($amount, $amountLocal)) {
$status = static::Status_Success;
} elseif (Number::floatsAreEqual($amount, $amountLocal, 0.02)) {
$status = static::Status_Info;
} elseif (Number::floatsAreEqual($amount, $amountLocal, 0.05)) {
$status = static::Status_Warning;
} else {
$status = static::Status_Error;
}
return $status;
} | php | private function getAmountStatus($amount, $amountLocal)
{
if (Number::floatsAreEqual($amount, $amountLocal)) {
$status = static::Status_Success;
} elseif (Number::floatsAreEqual($amount, $amountLocal, 0.02)) {
$status = static::Status_Info;
} elseif (Number::floatsAreEqual($amount, $amountLocal, 0.05)) {
$status = static::Status_Warning;
} else {
$status = static::Status_Error;
}
return $status;
} | [
"private",
"function",
"getAmountStatus",
"(",
"$",
"amount",
",",
"$",
"amountLocal",
")",
"{",
"if",
"(",
"Number",
"::",
"floatsAreEqual",
"(",
"$",
"amount",
",",
"$",
"amountLocal",
")",
")",
"{",
"$",
"status",
"=",
"static",
"::",
"Status_Success",
... | Returns the status of an amount by comparing it with its local value.
If the amounts differ:
- < 0.5 cent, they are considered equal and 'success' will be returned.
- < 2 cents, it is considered a mere rounding error and 'info' will be returned.
- < 5 cents, it is considered a probable error and 'warning' will be returned.
- >= 5 cents, it is considered an error and 'error' will be returned.
@param float $amount
@param float $amountLocal
@return int
One of the Status_... constants. | [
"Returns",
"the",
"status",
"of",
"an",
"amount",
"by",
"comparing",
"it",
"with",
"its",
"local",
"value",
"."
] | 82f8d6c9c4929c41948c97d6cfdfac3f27c37255 | https://github.com/SIELOnline/libAcumulus/blob/82f8d6c9c4929c41948c97d6cfdfac3f27c37255/src/WooCommerce/Shop/InvoiceStatusOverviewForm.php#L926-L938 | train |
SIELOnline/libAcumulus | src/WooCommerce/Shop/InvoiceStatusOverviewForm.php | InvoiceStatusOverviewForm.getLinksField | private function getLinksField($token)
{
$uri = $this->service->getInvoicePdfUri($token);
$text = ucfirst($this->t('invoice'));
$title = sprintf($this->t('open_as_pdf'), $text);
/** @noinspection HtmlUnknownTarget */
$invoiceLink = sprintf('<a class="%4$s" href="%1$s" title="%3$s">%2$s</a>', $uri, $text, $title, 'pdf');
$uri = $this->service->getPackingSlipUri($token);
$text = ucfirst($this->t('packing_slip'));
$title = sprintf($this->t('open_as_pdf'), $text);
/** @noinspection HtmlUnknownTarget */
$packingSlipLink = sprintf('<a class="%4$s" href="%1$s" title="%3$s">%2$s</a>', $uri, $text, $title, 'pdf');
$fields = array(
'links' => array(
'type' => 'markup',
'label' => $this->t('documents'),
'value' => "$invoiceLink $packingSlipLink",
),
);
return $fields;
} | php | private function getLinksField($token)
{
$uri = $this->service->getInvoicePdfUri($token);
$text = ucfirst($this->t('invoice'));
$title = sprintf($this->t('open_as_pdf'), $text);
/** @noinspection HtmlUnknownTarget */
$invoiceLink = sprintf('<a class="%4$s" href="%1$s" title="%3$s">%2$s</a>', $uri, $text, $title, 'pdf');
$uri = $this->service->getPackingSlipUri($token);
$text = ucfirst($this->t('packing_slip'));
$title = sprintf($this->t('open_as_pdf'), $text);
/** @noinspection HtmlUnknownTarget */
$packingSlipLink = sprintf('<a class="%4$s" href="%1$s" title="%3$s">%2$s</a>', $uri, $text, $title, 'pdf');
$fields = array(
'links' => array(
'type' => 'markup',
'label' => $this->t('documents'),
'value' => "$invoiceLink $packingSlipLink",
),
);
return $fields;
} | [
"private",
"function",
"getLinksField",
"(",
"$",
"token",
")",
"{",
"$",
"uri",
"=",
"$",
"this",
"->",
"service",
"->",
"getInvoicePdfUri",
"(",
"$",
"token",
")",
";",
"$",
"text",
"=",
"ucfirst",
"(",
"$",
"this",
"->",
"t",
"(",
"'invoice'",
")"... | Returns links to the invoice and packing slip documents.
@param string $token
@return array[]
Array with form field that contains links to documents related to this
invoice. | [
"Returns",
"links",
"to",
"the",
"invoice",
"and",
"packing",
"slip",
"documents",
"."
] | 82f8d6c9c4929c41948c97d6cfdfac3f27c37255 | https://github.com/SIELOnline/libAcumulus/blob/82f8d6c9c4929c41948c97d6cfdfac3f27c37255/src/WooCommerce/Shop/InvoiceStatusOverviewForm.php#L982-L1004 | train |
SIELOnline/libAcumulus | src/WooCommerce/Shop/InvoiceStatusOverviewForm.php | InvoiceStatusOverviewForm.sanitizeEntry | private function sanitizeEntry($entry)
{
if (!empty($entry)) {
/* @todo: keys in $entry array that are not yet used and not yet sanitized:
* - entrytype
* - entrydescription
* - entrynote
* - fiscaltype
* - contactid
* - accountnumber
* - costcenterid
* - costtypeid
* - invoicenote
* - descriptiontext
* - invoicelayoutid
* - token
* - paymenttermdays
*/
$result['entryid'] = $this->sanitizeEntryIntValue($entry, 'entryid');
$result['entrydate'] = $this->sanitizeEntryDateValue($entry, 'entrydate');
$result['vatreversecharge'] = $this->sanitizeEntryBoolValue($entry, 'vatreversecharge');
$result['foreigneu'] = $this->sanitizeEntryBoolValue($entry, 'foreigneu');
$result['foreignnoneu'] = $this->sanitizeEntryBoolValue($entry, 'foreignnoneu');
$result['marginscheme'] = $this->sanitizeEntryBoolValue($entry, 'marginscheme');
$result['foreignvat'] = $this->sanitizeEntryBoolValue($entry, 'foreignvat');
$result['invoicenumber'] = $this->sanitizeEntryIntValue($entry, 'invoicenumber');
$result['totalvalueexclvat'] = $this->sanitizeEntryFloatValue($entry, 'totalvalueexclvat');
$result['totalvalue'] = $this->sanitizeEntryFloatValue($entry, 'totalvalue');
$result['paymentstatus'] = $this->sanitizeEntryIntValue($entry, 'paymentstatus');
$result['paymentdate'] = $this->sanitizeEntryDateValue($entry, 'paymentdate');
$result['deleted'] = $this->sanitizeEntryStringValue($entry, 'deleted');
} else {
$result = null;
}
return $result;
} | php | private function sanitizeEntry($entry)
{
if (!empty($entry)) {
/* @todo: keys in $entry array that are not yet used and not yet sanitized:
* - entrytype
* - entrydescription
* - entrynote
* - fiscaltype
* - contactid
* - accountnumber
* - costcenterid
* - costtypeid
* - invoicenote
* - descriptiontext
* - invoicelayoutid
* - token
* - paymenttermdays
*/
$result['entryid'] = $this->sanitizeEntryIntValue($entry, 'entryid');
$result['entrydate'] = $this->sanitizeEntryDateValue($entry, 'entrydate');
$result['vatreversecharge'] = $this->sanitizeEntryBoolValue($entry, 'vatreversecharge');
$result['foreigneu'] = $this->sanitizeEntryBoolValue($entry, 'foreigneu');
$result['foreignnoneu'] = $this->sanitizeEntryBoolValue($entry, 'foreignnoneu');
$result['marginscheme'] = $this->sanitizeEntryBoolValue($entry, 'marginscheme');
$result['foreignvat'] = $this->sanitizeEntryBoolValue($entry, 'foreignvat');
$result['invoicenumber'] = $this->sanitizeEntryIntValue($entry, 'invoicenumber');
$result['totalvalueexclvat'] = $this->sanitizeEntryFloatValue($entry, 'totalvalueexclvat');
$result['totalvalue'] = $this->sanitizeEntryFloatValue($entry, 'totalvalue');
$result['paymentstatus'] = $this->sanitizeEntryIntValue($entry, 'paymentstatus');
$result['paymentdate'] = $this->sanitizeEntryDateValue($entry, 'paymentdate');
$result['deleted'] = $this->sanitizeEntryStringValue($entry, 'deleted');
} else {
$result = null;
}
return $result;
} | [
"private",
"function",
"sanitizeEntry",
"(",
"$",
"entry",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"entry",
")",
")",
"{",
"/* @todo: keys in $entry array that are not yet used and not yet sanitized:\n * - entrytype\n * - entrydescription\n ... | Sanitizes an entry struct received via an getEntry API call.
The info received from an external API call must not be trusted, so it
should be sanitized. As most info from this API call is placed in markup
fields we cannot rely on the FormRenderer or the webshop's form API
(which do not sanitize markup fields).
So we sanitize the values in the struct itself before using them:
- Int, float, and bool fields are cast to their proper type.
- Date strings are parsed to a DateTime and formatted back to a date
string.
- Strings that can only contain a restricted set of values are checked
against that set and emptied if not part of it.
- Free string values are escaped to save html.
- Keys we don't use are not returned. This keeps the output safe when a
future API version returns additional fields and we forget to sanitize
it and thus use it non sanitised.
@param $entry
@return mixed
The sanitized entry struct. | [
"Sanitizes",
"an",
"entry",
"struct",
"received",
"via",
"an",
"getEntry",
"API",
"call",
"."
] | 82f8d6c9c4929c41948c97d6cfdfac3f27c37255 | https://github.com/SIELOnline/libAcumulus/blob/82f8d6c9c4929c41948c97d6cfdfac3f27c37255/src/WooCommerce/Shop/InvoiceStatusOverviewForm.php#L1079-L1114 | train |
SIELOnline/libAcumulus | src/WooCommerce/Shop/InvoiceStatusOverviewForm.php | InvoiceStatusOverviewForm.sanitizeEntryStringValue | private function sanitizeEntryStringValue(array $entry, $key)
{
return !empty($entry[$key]) ? htmlspecialchars($entry[$key], ENT_NOQUOTES) : '';
} | php | private function sanitizeEntryStringValue(array $entry, $key)
{
return !empty($entry[$key]) ? htmlspecialchars($entry[$key], ENT_NOQUOTES) : '';
} | [
"private",
"function",
"sanitizeEntryStringValue",
"(",
"array",
"$",
"entry",
",",
"$",
"key",
")",
"{",
"return",
"!",
"empty",
"(",
"$",
"entry",
"[",
"$",
"key",
"]",
")",
"?",
"htmlspecialchars",
"(",
"$",
"entry",
"[",
"$",
"key",
"]",
",",
"EN... | Returns a html safe version of a string in an entry record.
@param array $entry
@param string $key
@return string
The html safe version of the value under this key or the empty string
if not set. | [
"Returns",
"a",
"html",
"safe",
"version",
"of",
"a",
"string",
"in",
"an",
"entry",
"record",
"."
] | 82f8d6c9c4929c41948c97d6cfdfac3f27c37255 | https://github.com/SIELOnline/libAcumulus/blob/82f8d6c9c4929c41948c97d6cfdfac3f27c37255/src/WooCommerce/Shop/InvoiceStatusOverviewForm.php#L1126-L1129 | train |
SIELOnline/libAcumulus | src/WooCommerce/Shop/InvoiceStatusOverviewForm.php | InvoiceStatusOverviewForm.sanitizeEntryDateValue | private function sanitizeEntryDateValue(array $entry, $key)
{
$date = '';
if (!empty($entry[$key])) {
$date = DateTime::createFromFormat(API::DateFormat_Iso, $entry[$key]);
if ($date instanceof DateTime) {
$date = $date->format(Api::DateFormat_Iso);
} else {
$date = '';
}
}
return $date;
} | php | private function sanitizeEntryDateValue(array $entry, $key)
{
$date = '';
if (!empty($entry[$key])) {
$date = DateTime::createFromFormat(API::DateFormat_Iso, $entry[$key]);
if ($date instanceof DateTime) {
$date = $date->format(Api::DateFormat_Iso);
} else {
$date = '';
}
}
return $date;
} | [
"private",
"function",
"sanitizeEntryDateValue",
"(",
"array",
"$",
"entry",
",",
"$",
"key",
")",
"{",
"$",
"date",
"=",
"''",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"entry",
"[",
"$",
"key",
"]",
")",
")",
"{",
"$",
"date",
"=",
"DateTime",
":... | Returns a sanitized date value of an entry record.
@param array $entry
@param string $key
@return string
The date value (yyyy-mm-dd) of the value under this key or the empty
string, if the string is not in the valid date format (yyyy-mm-dd). | [
"Returns",
"a",
"sanitized",
"date",
"value",
"of",
"an",
"entry",
"record",
"."
] | 82f8d6c9c4929c41948c97d6cfdfac3f27c37255 | https://github.com/SIELOnline/libAcumulus/blob/82f8d6c9c4929c41948c97d6cfdfac3f27c37255/src/WooCommerce/Shop/InvoiceStatusOverviewForm.php#L1185-L1197 | train |
SIELOnline/libAcumulus | src/Invoice/Completor.php | Completor.initPossibleVatTypes | protected function initPossibleVatTypes()
{
$possibleVatTypes = array();
$shopSettings = $this->config->getShopSettings();
$nature = $shopSettings['nature_shop'];
$margin = $shopSettings['marginProducts'];
$foreignVat = $shopSettings['foreignVat'];
if (!empty($this->invoice[Tag::Customer][Tag::Invoice][Tag::VatType])) {
// If shop specific code or an event handler has already set the vat
// type, we obey so.
$possibleVatTypes[] = $this->invoice[Tag::Customer][Tag::Invoice][Tag::VatType];
} else {
if ($this->isNl()) {
$possibleVatTypes[] = Api::VatType_National;
// Can it be national reversed VAT: not really supported but
// possible.
if ($this->isCompany()) {
$possibleVatTypes[] = Api::VatType_NationalReversed;
}
} elseif ($this->isEu()) {
// Can it be normal vat?
if ($foreignVat !== PluginConfig::ForeignVat_Only) {
$possibleVatTypes[] = Api::VatType_National;
}
// Can it be foreign vat?
if ($foreignVat !== PluginConfig::ForeignVat_No) {
$possibleVatTypes[] = Api::VatType_ForeignVat;
}
// Can it be EU reversed VAT.
if ($this->isCompany()) {
$possibleVatTypes[] = Api::VatType_EuReversed;
}
} elseif ($this->isOutsideEu()) {
// Can it be national vat (possibly vat free)? Services should
// use vattype = 1.
if ($nature !== PluginConfig::Nature_Products) {
$possibleVatTypes[] = Api::VatType_National;
}
// Can it be rest of world (0%)? Goods should use vat type = 4
// unless you can't or don't want to prove that the goods will
// leave the EU (see
// https://www.belastingdienst.nl/rekenhulpen/leveren_van_goederen_naar_het_buitenland/),
// in which case we should use vat type = 1.
if ($nature !== PluginConfig::Nature_Services) {
$possibleVatTypes[] = Api::VatType_National;
$possibleVatTypes[] = Api::VatType_RestOfWorld;
}
}
// Can it be a margin invoice?
if ($margin !== PluginConfig::MarginProducts_No) {
$possibleVatTypes[] = Api::VatType_MarginScheme;
}
}
$this->possibleVatTypes = array_unique($possibleVatTypes, SORT_NUMERIC);
} | php | protected function initPossibleVatTypes()
{
$possibleVatTypes = array();
$shopSettings = $this->config->getShopSettings();
$nature = $shopSettings['nature_shop'];
$margin = $shopSettings['marginProducts'];
$foreignVat = $shopSettings['foreignVat'];
if (!empty($this->invoice[Tag::Customer][Tag::Invoice][Tag::VatType])) {
// If shop specific code or an event handler has already set the vat
// type, we obey so.
$possibleVatTypes[] = $this->invoice[Tag::Customer][Tag::Invoice][Tag::VatType];
} else {
if ($this->isNl()) {
$possibleVatTypes[] = Api::VatType_National;
// Can it be national reversed VAT: not really supported but
// possible.
if ($this->isCompany()) {
$possibleVatTypes[] = Api::VatType_NationalReversed;
}
} elseif ($this->isEu()) {
// Can it be normal vat?
if ($foreignVat !== PluginConfig::ForeignVat_Only) {
$possibleVatTypes[] = Api::VatType_National;
}
// Can it be foreign vat?
if ($foreignVat !== PluginConfig::ForeignVat_No) {
$possibleVatTypes[] = Api::VatType_ForeignVat;
}
// Can it be EU reversed VAT.
if ($this->isCompany()) {
$possibleVatTypes[] = Api::VatType_EuReversed;
}
} elseif ($this->isOutsideEu()) {
// Can it be national vat (possibly vat free)? Services should
// use vattype = 1.
if ($nature !== PluginConfig::Nature_Products) {
$possibleVatTypes[] = Api::VatType_National;
}
// Can it be rest of world (0%)? Goods should use vat type = 4
// unless you can't or don't want to prove that the goods will
// leave the EU (see
// https://www.belastingdienst.nl/rekenhulpen/leveren_van_goederen_naar_het_buitenland/),
// in which case we should use vat type = 1.
if ($nature !== PluginConfig::Nature_Services) {
$possibleVatTypes[] = Api::VatType_National;
$possibleVatTypes[] = Api::VatType_RestOfWorld;
}
}
// Can it be a margin invoice?
if ($margin !== PluginConfig::MarginProducts_No) {
$possibleVatTypes[] = Api::VatType_MarginScheme;
}
}
$this->possibleVatTypes = array_unique($possibleVatTypes, SORT_NUMERIC);
} | [
"protected",
"function",
"initPossibleVatTypes",
"(",
")",
"{",
"$",
"possibleVatTypes",
"=",
"array",
"(",
")",
";",
"$",
"shopSettings",
"=",
"$",
"this",
"->",
"config",
"->",
"getShopSettings",
"(",
")",
";",
"$",
"nature",
"=",
"$",
"shopSettings",
"[... | Initializes the list of possible vat types for this invoice.
The list of possible vat types depends on:
- Whether the vat type already has been set.
- Whether there is at least 1 line with a costprice.
- The country of the client.
- Whether the client is a company.
- The shop settings (selling foreign vat or vat free products).
- Optionally, the date of the invoice.
See also: {@see https://wiki.acumulus.nl/index.php?page=facturen-naar-het-buitenland}. | [
"Initializes",
"the",
"list",
"of",
"possible",
"vat",
"types",
"for",
"this",
"invoice",
"."
] | 82f8d6c9c4929c41948c97d6cfdfac3f27c37255 | https://github.com/SIELOnline/libAcumulus/blob/82f8d6c9c4929c41948c97d6cfdfac3f27c37255/src/Invoice/Completor.php#L263-L319 | train |
SIELOnline/libAcumulus | src/Invoice/Completor.php | Completor.initPossibleVatRates | protected function initPossibleVatRates()
{
$possibleVatRates = array();
$shopSettings = $this->config->getShopSettings();
$nature = $shopSettings['nature_shop'];
$vatFreeProducts = $shopSettings['vatFreeProducts'];
foreach ($this->possibleVatTypes as $vatType) {
switch ($vatType) {
case Api::VatType_National:
case Api::VatType_MarginScheme:
$vatTypeVatRates = $this->getVatRatesByCountryAndDate('nl');
// Add vat free (-1):
// - if selling vat free products/services
// - OR if outside EU AND (services OR company).
if ($vatFreeProducts != PluginConfig::VatFreeProducts_No) {
$vatTypeVatRates[] = -1;
} elseif ($this->isOutsideEu() && ($nature !== PluginConfig::Nature_Products || $this->isCompany())) {
$vatTypeVatRates[] = -1;
}
break;
case Api::VatType_NationalReversed:
case Api::VatType_EuReversed:
case Api::VatType_RestOfWorld:
$vatTypeVatRates = array(0);
break;
case Api::VatType_ForeignVat:
$vatTypeVatRates = $this->getVatRatesByCountryAndDate($this->invoice[Tag::Customer][Tag::CountryCode]);
break;
default:
$vatTypeVatRates = array();
$this->log->error('Completor::initPossibleVatRates(): unknown vat type %d', $vatType);
break;
}
// convert the list of vat rates to a list of vat rate infos.
foreach ($vatTypeVatRates as &$vatRate) {
$vatRate = array(Tag::VatRate => $vatRate, Tag::VatType => $vatType);
}
$possibleVatRates = array_merge($possibleVatRates, $vatTypeVatRates);
}
$this->possibleVatRates = $possibleVatRates;
} | php | protected function initPossibleVatRates()
{
$possibleVatRates = array();
$shopSettings = $this->config->getShopSettings();
$nature = $shopSettings['nature_shop'];
$vatFreeProducts = $shopSettings['vatFreeProducts'];
foreach ($this->possibleVatTypes as $vatType) {
switch ($vatType) {
case Api::VatType_National:
case Api::VatType_MarginScheme:
$vatTypeVatRates = $this->getVatRatesByCountryAndDate('nl');
// Add vat free (-1):
// - if selling vat free products/services
// - OR if outside EU AND (services OR company).
if ($vatFreeProducts != PluginConfig::VatFreeProducts_No) {
$vatTypeVatRates[] = -1;
} elseif ($this->isOutsideEu() && ($nature !== PluginConfig::Nature_Products || $this->isCompany())) {
$vatTypeVatRates[] = -1;
}
break;
case Api::VatType_NationalReversed:
case Api::VatType_EuReversed:
case Api::VatType_RestOfWorld:
$vatTypeVatRates = array(0);
break;
case Api::VatType_ForeignVat:
$vatTypeVatRates = $this->getVatRatesByCountryAndDate($this->invoice[Tag::Customer][Tag::CountryCode]);
break;
default:
$vatTypeVatRates = array();
$this->log->error('Completor::initPossibleVatRates(): unknown vat type %d', $vatType);
break;
}
// convert the list of vat rates to a list of vat rate infos.
foreach ($vatTypeVatRates as &$vatRate) {
$vatRate = array(Tag::VatRate => $vatRate, Tag::VatType => $vatType);
}
$possibleVatRates = array_merge($possibleVatRates, $vatTypeVatRates);
}
$this->possibleVatRates = $possibleVatRates;
} | [
"protected",
"function",
"initPossibleVatRates",
"(",
")",
"{",
"$",
"possibleVatRates",
"=",
"array",
"(",
")",
";",
"$",
"shopSettings",
"=",
"$",
"this",
"->",
"config",
"->",
"getShopSettings",
"(",
")",
";",
"$",
"nature",
"=",
"$",
"shopSettings",
"[... | Initializes the list of possible vat rates.
The possible vat rates depend on:
- the possible vat types.
- optionally, the date of the invoice.
- optionally, the country of the client.
- optionally, the nature of the articles sold.
On finishing, $this->possibleVatRates will contain an array with possible
vat rates. A vat rate being an array with keys vatrate and vattype. This
is done so to be able to determine to which vat type(s) a vat rate
belongs. | [
"Initializes",
"the",
"list",
"of",
"possible",
"vat",
"rates",
"."
] | 82f8d6c9c4929c41948c97d6cfdfac3f27c37255 | https://github.com/SIELOnline/libAcumulus/blob/82f8d6c9c4929c41948c97d6cfdfac3f27c37255/src/Invoice/Completor.php#L335-L377 | train |
SIELOnline/libAcumulus | src/Invoice/Completor.php | Completor.fictitiousClient | protected function fictitiousClient()
{
$customerSettings = $this->config->getCustomerSettings();
if (!$customerSettings['sendCustomer'] && !$this->isCompany()) {
$keysToKeep = array(Tag::CountryCode, Tag::Invoice);
foreach ($this->invoice[Tag::Customer] as $key => $value) {
if (!in_array($key, $keysToKeep)) {
unset($this->invoice[Tag::Customer][$key]);
}
}
$this->invoice[Tag::Customer][Tag::Email] = $customerSettings['genericCustomerEmail'];
$this->invoice[Tag::Customer][Tag::ContactStatus] = Api::ContactStatus_Disabled;
$this->invoice[Tag::Customer][Tag::OverwriteIfExists] = Api::OverwriteIfExists_No;
}
} | php | protected function fictitiousClient()
{
$customerSettings = $this->config->getCustomerSettings();
if (!$customerSettings['sendCustomer'] && !$this->isCompany()) {
$keysToKeep = array(Tag::CountryCode, Tag::Invoice);
foreach ($this->invoice[Tag::Customer] as $key => $value) {
if (!in_array($key, $keysToKeep)) {
unset($this->invoice[Tag::Customer][$key]);
}
}
$this->invoice[Tag::Customer][Tag::Email] = $customerSettings['genericCustomerEmail'];
$this->invoice[Tag::Customer][Tag::ContactStatus] = Api::ContactStatus_Disabled;
$this->invoice[Tag::Customer][Tag::OverwriteIfExists] = Api::OverwriteIfExists_No;
}
} | [
"protected",
"function",
"fictitiousClient",
"(",
")",
"{",
"$",
"customerSettings",
"=",
"$",
"this",
"->",
"config",
"->",
"getCustomerSettings",
"(",
")",
";",
"if",
"(",
"!",
"$",
"customerSettings",
"[",
"'sendCustomer'",
"]",
"&&",
"!",
"$",
"this",
... | Anonymize customer if set so.
- We don't do this for business clients, only consumers.
- We keep the country code as it is needed to determine the vat type. | [
"Anonymize",
"customer",
"if",
"set",
"so",
"."
] | 82f8d6c9c4929c41948c97d6cfdfac3f27c37255 | https://github.com/SIELOnline/libAcumulus/blob/82f8d6c9c4929c41948c97d6cfdfac3f27c37255/src/Invoice/Completor.php#L385-L399 | train |
SIELOnline/libAcumulus | src/Invoice/Completor.php | Completor.validateEmail | protected function validateEmail()
{
// Check email address.
if (empty($this->invoice[Tag::Customer][Tag::Email])) {
$customerSettings = $this->config->getCustomerSettings();
$this->invoice[Tag::Customer][Tag::Email] = $customerSettings['emailIfAbsent'];
$this->result->addWarning(801,'', $this->t('message_warning_no_email'));
} else {
$email = $this->invoice[Tag::Customer][Tag::Email];
$at = strpos($email, '@');
// Comma (,) used as separator?
$comma = strpos($email, ',', $at);
if ($at < $comma) {
$email = trim(substr($email, 0, $comma));
}
// Semicolon (;) used as separator?
$semicolon = strpos($email, ';', $at);
if ($at < $semicolon) {
$email = trim(substr($email, 0, $semicolon));
}
// Display name used in single remaining address?
if (preg_match('/^(.+?)<([^>]+)>$/', $email, $matches)) {
$email = trim($matches[2]);
}
$this->invoice[Tag::Customer][Tag::Email] = $email;
}
} | php | protected function validateEmail()
{
// Check email address.
if (empty($this->invoice[Tag::Customer][Tag::Email])) {
$customerSettings = $this->config->getCustomerSettings();
$this->invoice[Tag::Customer][Tag::Email] = $customerSettings['emailIfAbsent'];
$this->result->addWarning(801,'', $this->t('message_warning_no_email'));
} else {
$email = $this->invoice[Tag::Customer][Tag::Email];
$at = strpos($email, '@');
// Comma (,) used as separator?
$comma = strpos($email, ',', $at);
if ($at < $comma) {
$email = trim(substr($email, 0, $comma));
}
// Semicolon (;) used as separator?
$semicolon = strpos($email, ';', $at);
if ($at < $semicolon) {
$email = trim(substr($email, 0, $semicolon));
}
// Display name used in single remaining address?
if (preg_match('/^(.+?)<([^>]+)>$/', $email, $matches)) {
$email = trim($matches[2]);
}
$this->invoice[Tag::Customer][Tag::Email] = $email;
}
} | [
"protected",
"function",
"validateEmail",
"(",
")",
"{",
"// Check email address.",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"invoice",
"[",
"Tag",
"::",
"Customer",
"]",
"[",
"Tag",
"::",
"Email",
"]",
")",
")",
"{",
"$",
"customerSettings",
"=",
"$"... | Validates the email address of the invoice.
Validations performed:
- Multiple, comma separated, email addresses are not allowed.
- Display names (My Name <my.name@example.com>) are not allowed.
- The email address may not be empty but may be left out though in which
case a new relation will be created. To prevent both, we use a fake
address and we will set a warning. | [
"Validates",
"the",
"email",
"address",
"of",
"the",
"invoice",
"."
] | 82f8d6c9c4929c41948c97d6cfdfac3f27c37255 | https://github.com/SIELOnline/libAcumulus/blob/82f8d6c9c4929c41948c97d6cfdfac3f27c37255/src/Invoice/Completor.php#L411-L438 | train |
SIELOnline/libAcumulus | src/Invoice/Completor.php | Completor.invoiceTemplate | protected function invoiceTemplate()
{
$invoiceSettings = $this->config->getInvoiceSettings();
// Acumulus invoice template to use.
$settingToUse = isset($this->invoice[Tag::Customer][Tag::Invoice][Tag::PaymentStatus])
&& $this->invoice[Tag::Customer][Tag::Invoice][Tag::PaymentStatus] == Api::PaymentStatus_Paid
// 0 (= empty) = use same invoice template as for non paid invoices.
&& $invoiceSettings['defaultInvoicePaidTemplate'] != 0
? 'defaultInvoicePaidTemplate'
: 'defaultInvoiceTemplate';
$this->addDefault($this->invoice[Tag::Customer][Tag::Invoice], Tag::Template, $invoiceSettings[$settingToUse]);
} | php | protected function invoiceTemplate()
{
$invoiceSettings = $this->config->getInvoiceSettings();
// Acumulus invoice template to use.
$settingToUse = isset($this->invoice[Tag::Customer][Tag::Invoice][Tag::PaymentStatus])
&& $this->invoice[Tag::Customer][Tag::Invoice][Tag::PaymentStatus] == Api::PaymentStatus_Paid
// 0 (= empty) = use same invoice template as for non paid invoices.
&& $invoiceSettings['defaultInvoicePaidTemplate'] != 0
? 'defaultInvoicePaidTemplate'
: 'defaultInvoiceTemplate';
$this->addDefault($this->invoice[Tag::Customer][Tag::Invoice], Tag::Template, $invoiceSettings[$settingToUse]);
} | [
"protected",
"function",
"invoiceTemplate",
"(",
")",
"{",
"$",
"invoiceSettings",
"=",
"$",
"this",
"->",
"config",
"->",
"getInvoiceSettings",
"(",
")",
";",
"// Acumulus invoice template to use.",
"$",
"settingToUse",
"=",
"isset",
"(",
"$",
"this",
"->",
"in... | Fills the invoice template to use when sending an invoice from Acumulus.
As getting the payment status right is notoriously hard, we fill this
value only here in the completor phase to give users the chance to change
the payment status in the acumulus invoice created event. | [
"Fills",
"the",
"invoice",
"template",
"to",
"use",
"when",
"sending",
"an",
"invoice",
"from",
"Acumulus",
"."
] | 82f8d6c9c4929c41948c97d6cfdfac3f27c37255 | https://github.com/SIELOnline/libAcumulus/blob/82f8d6c9c4929c41948c97d6cfdfac3f27c37255/src/Invoice/Completor.php#L447-L459 | train |
SIELOnline/libAcumulus | src/Invoice/Completor.php | Completor.checkMissingAmount | protected function checkMissingAmount()
{
// Check if we are missing an amount and, if so, add a line for it.
$this->completeLineTotals();
$areTotalsEqual = $this->areTotalsEqual();
if ($areTotalsEqual === false) {
$this->addMissingAmountLine();
}
} | php | protected function checkMissingAmount()
{
// Check if we are missing an amount and, if so, add a line for it.
$this->completeLineTotals();
$areTotalsEqual = $this->areTotalsEqual();
if ($areTotalsEqual === false) {
$this->addMissingAmountLine();
}
} | [
"protected",
"function",
"checkMissingAmount",
"(",
")",
"{",
"// Check if we are missing an amount and, if so, add a line for it.",
"$",
"this",
"->",
"completeLineTotals",
"(",
")",
";",
"$",
"areTotalsEqual",
"=",
"$",
"this",
"->",
"areTotalsEqual",
"(",
")",
";",
... | Checks for a missing amount and handles it. | [
"Checks",
"for",
"a",
"missing",
"amount",
"and",
"handles",
"it",
"."
] | 82f8d6c9c4929c41948c97d6cfdfac3f27c37255 | https://github.com/SIELOnline/libAcumulus/blob/82f8d6c9c4929c41948c97d6cfdfac3f27c37255/src/Invoice/Completor.php#L486-L494 | train |
SIELOnline/libAcumulus | src/Invoice/Completor.php | Completor.completeLineTotals | protected function completeLineTotals()
{
$linesAmount = 0.0;
$linesAmountInc = 0.0;
$linesVatAmount = 0.0;
$this->lineTotalsStates = array(
'incomplete' => array(),
'equal' => array(),
'differ' => array(),
);
$invoiceLines = $this->invoice[Tag::Customer][Tag::Invoice][Tag::Line];
foreach ($invoiceLines as $line) {
if (isset($line[Meta::LineAmount])) {
$linesAmount += $line[Meta::LineAmount];
} elseif (isset($line[Tag::UnitPrice])) {
$linesAmount += $line[Tag::Quantity] * $line[Tag::UnitPrice];
} else {
$this->lineTotalsStates['incomplete'][Meta::LinesAmount] = Meta::LinesAmount;
}
if (isset($line[Meta::LineAmountInc])) {
$linesAmountInc += $line[Meta::LineAmountInc];
} elseif (isset($line[Meta::UnitPriceInc])) {
$linesAmountInc += $line[Tag::Quantity] * $line[Meta::UnitPriceInc];
} else {
$this->lineTotalsStates['incomplete'][Meta::LinesAmountInc] = Meta::LinesAmountInc;
}
if (isset($line[Meta::LineVatAmount])) {
$linesVatAmount += $line[Meta::LineVatAmount];
} elseif (isset($line[Meta::VatAmount])) {
$linesVatAmount += $line[Tag::Quantity] * $line[Meta::VatAmount];
} else {
$this->lineTotalsStates['incomplete'][Meta::LinesVatAmount] = Meta::LinesVatAmount;
}
}
$this->invoice[Tag::Customer][Tag::Invoice][Meta::LinesAmount ] = $linesAmount;
$this->invoice[Tag::Customer][Tag::Invoice][Meta::LinesAmountInc] = $linesAmountInc;
$this->invoice[Tag::Customer][Tag::Invoice][Meta::LinesVatAmount] = $linesVatAmount;
if (!empty($this->lineTotalsStates['incomplete'])) {
sort($this->lineTotalsStates['incomplete']);
$this->invoice[Tag::Customer][Tag::Invoice][Meta::LinesIncomplete] = implode(',', $this->lineTotalsStates['incomplete']);
}
} | php | protected function completeLineTotals()
{
$linesAmount = 0.0;
$linesAmountInc = 0.0;
$linesVatAmount = 0.0;
$this->lineTotalsStates = array(
'incomplete' => array(),
'equal' => array(),
'differ' => array(),
);
$invoiceLines = $this->invoice[Tag::Customer][Tag::Invoice][Tag::Line];
foreach ($invoiceLines as $line) {
if (isset($line[Meta::LineAmount])) {
$linesAmount += $line[Meta::LineAmount];
} elseif (isset($line[Tag::UnitPrice])) {
$linesAmount += $line[Tag::Quantity] * $line[Tag::UnitPrice];
} else {
$this->lineTotalsStates['incomplete'][Meta::LinesAmount] = Meta::LinesAmount;
}
if (isset($line[Meta::LineAmountInc])) {
$linesAmountInc += $line[Meta::LineAmountInc];
} elseif (isset($line[Meta::UnitPriceInc])) {
$linesAmountInc += $line[Tag::Quantity] * $line[Meta::UnitPriceInc];
} else {
$this->lineTotalsStates['incomplete'][Meta::LinesAmountInc] = Meta::LinesAmountInc;
}
if (isset($line[Meta::LineVatAmount])) {
$linesVatAmount += $line[Meta::LineVatAmount];
} elseif (isset($line[Meta::VatAmount])) {
$linesVatAmount += $line[Tag::Quantity] * $line[Meta::VatAmount];
} else {
$this->lineTotalsStates['incomplete'][Meta::LinesVatAmount] = Meta::LinesVatAmount;
}
}
$this->invoice[Tag::Customer][Tag::Invoice][Meta::LinesAmount ] = $linesAmount;
$this->invoice[Tag::Customer][Tag::Invoice][Meta::LinesAmountInc] = $linesAmountInc;
$this->invoice[Tag::Customer][Tag::Invoice][Meta::LinesVatAmount] = $linesVatAmount;
if (!empty($this->lineTotalsStates['incomplete'])) {
sort($this->lineTotalsStates['incomplete']);
$this->invoice[Tag::Customer][Tag::Invoice][Meta::LinesIncomplete] = implode(',', $this->lineTotalsStates['incomplete']);
}
} | [
"protected",
"function",
"completeLineTotals",
"(",
")",
"{",
"$",
"linesAmount",
"=",
"0.0",
";",
"$",
"linesAmountInc",
"=",
"0.0",
";",
"$",
"linesVatAmount",
"=",
"0.0",
";",
"$",
"this",
"->",
"lineTotalsStates",
"=",
"array",
"(",
"'incomplete'",
"=>",... | Calculates the total amount and vat amount for the invoice lines and adds
these to the fields meta-lines-amount and meta-lines-vatamount. | [
"Calculates",
"the",
"total",
"amount",
"and",
"vat",
"amount",
"for",
"the",
"invoice",
"lines",
"and",
"adds",
"these",
"to",
"the",
"fields",
"meta",
"-",
"lines",
"-",
"amount",
"and",
"meta",
"-",
"lines",
"-",
"vatamount",
"."
] | 82f8d6c9c4929c41948c97d6cfdfac3f27c37255 | https://github.com/SIELOnline/libAcumulus/blob/82f8d6c9c4929c41948c97d6cfdfac3f27c37255/src/Invoice/Completor.php#L500-L545 | train |
SIELOnline/libAcumulus | src/Invoice/Completor.php | Completor.areTotalsEqual | protected function areTotalsEqual()
{
$invoice = $this->invoice[Tag::Customer][Tag::Invoice];
if (!in_array(Meta::LinesAmount, $this->lineTotalsStates['incomplete'])) {
if (Number::floatsAreEqual($invoice[Meta::InvoiceAmount], $invoice[Meta::LinesAmount], 0.05)) {
$this->lineTotalsStates['equal'][Meta::LinesAmount] = Meta::InvoiceAmount;
} else {
$this->lineTotalsStates['differ'][Meta::LinesAmount] = $invoice[Meta::InvoiceAmount] - $invoice[Meta::LinesAmount];
}
}
if (!in_array(Meta::LinesAmountInc, $this->lineTotalsStates['incomplete'])) {
if (Number::floatsAreEqual($invoice[Meta::InvoiceAmountInc], $invoice[Meta::LinesAmountInc], 0.05)) {
$this->lineTotalsStates['equal'][Meta::LinesAmountInc] = Meta::InvoiceAmountInc;
} else {
$this->lineTotalsStates['differ'][Meta::LinesAmountInc] = $invoice[Meta::InvoiceAmountInc] - $invoice[Meta::LinesAmountInc];
}
}
if (!in_array(Meta::LinesVatAmount, $this->lineTotalsStates['incomplete'])) {
if (Number::floatsAreEqual($invoice[Meta::InvoiceVatAmount], $invoice[Meta::LinesVatAmount], 0.05)) {
$this->lineTotalsStates['equal'][Meta::LinesVatAmount] = Meta::InvoiceVatAmount;
} else {
$this->lineTotalsStates['differ'][Meta::LinesVatAmount] = $invoice[Meta::InvoiceVatAmount] - $invoice[Meta::LinesVatAmount];
}
}
$equal = count($this->lineTotalsStates['equal']);
$differ = count($this->lineTotalsStates['differ']);
if ($differ > 0) {
$result = false;
} elseif ($equal > 0) {
// If only the vat amounts are equal, while the vat amount = 0, we
// cannot decide that the totals are equal because this appears to
// be a vat free/reversed vat invoice without any vatamount.
$result = $equal === 1 && array_key_exists(Meta::InvoiceVatAmount, $this->lineTotalsStates['differ']) && Number::isZero($invoice[Meta::LinesVatAmount])
? null
: true;
} else {
// No equal amounts nor different amounts found: undecided.
$result = null;
}
return $result;
} | php | protected function areTotalsEqual()
{
$invoice = $this->invoice[Tag::Customer][Tag::Invoice];
if (!in_array(Meta::LinesAmount, $this->lineTotalsStates['incomplete'])) {
if (Number::floatsAreEqual($invoice[Meta::InvoiceAmount], $invoice[Meta::LinesAmount], 0.05)) {
$this->lineTotalsStates['equal'][Meta::LinesAmount] = Meta::InvoiceAmount;
} else {
$this->lineTotalsStates['differ'][Meta::LinesAmount] = $invoice[Meta::InvoiceAmount] - $invoice[Meta::LinesAmount];
}
}
if (!in_array(Meta::LinesAmountInc, $this->lineTotalsStates['incomplete'])) {
if (Number::floatsAreEqual($invoice[Meta::InvoiceAmountInc], $invoice[Meta::LinesAmountInc], 0.05)) {
$this->lineTotalsStates['equal'][Meta::LinesAmountInc] = Meta::InvoiceAmountInc;
} else {
$this->lineTotalsStates['differ'][Meta::LinesAmountInc] = $invoice[Meta::InvoiceAmountInc] - $invoice[Meta::LinesAmountInc];
}
}
if (!in_array(Meta::LinesVatAmount, $this->lineTotalsStates['incomplete'])) {
if (Number::floatsAreEqual($invoice[Meta::InvoiceVatAmount], $invoice[Meta::LinesVatAmount], 0.05)) {
$this->lineTotalsStates['equal'][Meta::LinesVatAmount] = Meta::InvoiceVatAmount;
} else {
$this->lineTotalsStates['differ'][Meta::LinesVatAmount] = $invoice[Meta::InvoiceVatAmount] - $invoice[Meta::LinesVatAmount];
}
}
$equal = count($this->lineTotalsStates['equal']);
$differ = count($this->lineTotalsStates['differ']);
if ($differ > 0) {
$result = false;
} elseif ($equal > 0) {
// If only the vat amounts are equal, while the vat amount = 0, we
// cannot decide that the totals are equal because this appears to
// be a vat free/reversed vat invoice without any vatamount.
$result = $equal === 1 && array_key_exists(Meta::InvoiceVatAmount, $this->lineTotalsStates['differ']) && Number::isZero($invoice[Meta::LinesVatAmount])
? null
: true;
} else {
// No equal amounts nor different amounts found: undecided.
$result = null;
}
return $result;
} | [
"protected",
"function",
"areTotalsEqual",
"(",
")",
"{",
"$",
"invoice",
"=",
"$",
"this",
"->",
"invoice",
"[",
"Tag",
"::",
"Customer",
"]",
"[",
"Tag",
"::",
"Invoice",
"]",
";",
"if",
"(",
"!",
"in_array",
"(",
"Meta",
"::",
"LinesAmount",
",",
... | Compares the invoice totals metadata with the line totals metadata.
If any of the 3 values are equal we do consider the totals to be equal
(except for a 0 VAT amount (for reversed VAT invoices)). This because in
many cases 1 or 2 of the 3 values are either incomplete or incorrect.
@return bool|null
True if the totals are equal, false if not equal, null if undecided
(all 3 values are incomplete). | [
"Compares",
"the",
"invoice",
"totals",
"metadata",
"with",
"the",
"line",
"totals",
"metadata",
"."
] | 82f8d6c9c4929c41948c97d6cfdfac3f27c37255 | https://github.com/SIELOnline/libAcumulus/blob/82f8d6c9c4929c41948c97d6cfdfac3f27c37255/src/Invoice/Completor.php#L558-L600 | train |
SIELOnline/libAcumulus | src/Invoice/Completor.php | Completor.completeVatType | protected function completeVatType()
{
// If shop specific code or an event handler has already set the vat
// type, we don't change it.
if (empty($this->invoice[Tag::Customer][Tag::Invoice][Tag::VatType])) {
// @todo: if we only have one possible vattype, should we use that, or
// should we perform all checks to look for contradictory evidence?
$vatTypeInfo = $this->getInvoiceLinesVatTypeInfo();
$message = '';
$code = 0;
if (count($vatTypeInfo['intersection']) === 0) {
// No single vat type is correct for all lines, use the
// union to guess what went wrong.
if (count($vatTypeInfo['union']) === 0) {
// None of the vat rates of the invoice lines could be
// matched with any vat rate for any possible vat type.
// Possible causes:
// - Invoice has no vat but cannot be a reversed vat invoice
// nor outside the EU, nor are vat free products or
// services sold. Message: 'Check "about your shop"
// settings or the vat rates assigned to your products.'
// - Vat rates are incorrect for given country (and date).
// Message: 'Did you configure the correct settings for
// country ..?' or 'Were there recent changes in tax
// rates?'.
// - Vat rates are for foreign VAT but the shop does
// not sell foreign VAT products. Message'Check "about
// your shop" settings'.
// - Vat rates are Dutch vat rates but shop only sells
// foreign VAT products and client is in the EU. Message:
// 'Check the vat rates assigned to your products.'.
$message = 'message_warning_no_vattype_at_all';
$code = 804;
} elseif (count($vatTypeInfo['union']) === 1) {
// One or more lines could be matched with exactly 1 vat
// type, but not all lines.
// Possible causes:
// - Non matching lines have no vat. Message: 'Manual line
// entered without vat' or 'Check vat settings on those
// products.'.
// - Non matching lines have vat. Message: 'Manual line
// entered with incorrect vat' or 'Check vat settings on
// those products.'.
$this->invoice[Tag::Customer][Tag::Invoice][Tag::VatType] = reset($vatTypeInfo['union']);
$message = 'message_warning_no_vattype_incorrect_lines';
$code = 812;
} else {
// Separate lines could be matched with some of the possible
// vat types, but not all with the same vat type.
// Possible causes:
// - Mix of foreign VAT rates and other goods or services.
// Message: 'Split invoice.'.
// - Some lines have no vat but no vat free goods or
// services are sold and thus this could be a reversed vat
// (company in EU) or vat free invoice (outside EU).
// Message: check vat settings.
// - Mix of margin scheme and normal vat: this can be solved
// by making it a margin scheme invoice and adding
// costprice = 0 to all normal lines.
if (in_array(Api::VatType_MarginScheme, $vatTypeInfo['union'])) {
$this->invoice[Tag::Customer][Tag::Invoice][Tag::VatType] = Api::VatType_MarginScheme;
} else {
// Take the first vat type as a guess but add a warning.
$this->invoice[Tag::Customer][Tag::Invoice][Tag::VatType] = reset($vatTypeInfo['union']);
$message = 'message_warning_no_vattype_must_split';
$code = 806;
}
}
} elseif (count($vatTypeInfo['intersection']) === 1) {
// Exactly 1 vat type was found to be possible for all lines:
// use that one as the vat type for the invoice.
$this->invoice[Tag::Customer][Tag::Invoice][Tag::VatType] = reset($vatTypeInfo['intersection']);
} else {
// Multiple vat types were found to be possible for all lines:
// Take one and add a warning.
// Possible causes:
// - Client country has same vat rates as the Netherlands and
// shop sells products at foreign vat rates but also other
// products or services. Solvable by correct shop settings.
// - Invoice has no vat and the client is outside the EU and it
// is unknown whether the invoice lines contain services or
// goods. Perhaps solvable by correct shop settings.
// - Margin invoice: all lines that have a costprice will
// probably also satisfy the normal vat. This is solvable by
// making it a margin scheme invoice and adding costprice = 0
// to all normal lines.
if (in_array(Api::VatType_MarginScheme, $vatTypeInfo['union'])) {
$this->invoice[Tag::Customer][Tag::Invoice][Tag::VatType] = Api::VatType_MarginScheme;
} else {
// Take the first vat type as a guess but add a warning.
$this->invoice[Tag::Customer][Tag::Invoice][Tag::VatType] = reset($vatTypeInfo['intersection']);
$message = 'message_warning_no_vattype_multiple_possible';
$code = 811;
}
}
if (!empty($message)) {
// Make the invoice a concept, so it can be changed in Acumulus
// and add message and meta info.
$startSentence = count($vatTypeInfo['intersection']) === 0
? 'message_warning_no_vattype'
: 'message_warning_multiple_vattypes';
$this->changeInvoiceToConcept($message, $code, $this->t($startSentence));
}
$this->invoice[Tag::Customer][Tag::Invoice][Meta::VatTypesPossibleInvoice] = implode(',', $this->possibleVatTypes);
$this->invoice[Tag::Customer][Tag::Invoice][Meta::VatTypesPossibleInvoiceLinesIntersection] = implode(',', $vatTypeInfo['intersection']);
$this->invoice[Tag::Customer][Tag::Invoice][Meta::VatTypesPossibleInvoiceLinesUnion] = implode(',', $vatTypeInfo['union']);
}
} | php | protected function completeVatType()
{
// If shop specific code or an event handler has already set the vat
// type, we don't change it.
if (empty($this->invoice[Tag::Customer][Tag::Invoice][Tag::VatType])) {
// @todo: if we only have one possible vattype, should we use that, or
// should we perform all checks to look for contradictory evidence?
$vatTypeInfo = $this->getInvoiceLinesVatTypeInfo();
$message = '';
$code = 0;
if (count($vatTypeInfo['intersection']) === 0) {
// No single vat type is correct for all lines, use the
// union to guess what went wrong.
if (count($vatTypeInfo['union']) === 0) {
// None of the vat rates of the invoice lines could be
// matched with any vat rate for any possible vat type.
// Possible causes:
// - Invoice has no vat but cannot be a reversed vat invoice
// nor outside the EU, nor are vat free products or
// services sold. Message: 'Check "about your shop"
// settings or the vat rates assigned to your products.'
// - Vat rates are incorrect for given country (and date).
// Message: 'Did you configure the correct settings for
// country ..?' or 'Were there recent changes in tax
// rates?'.
// - Vat rates are for foreign VAT but the shop does
// not sell foreign VAT products. Message'Check "about
// your shop" settings'.
// - Vat rates are Dutch vat rates but shop only sells
// foreign VAT products and client is in the EU. Message:
// 'Check the vat rates assigned to your products.'.
$message = 'message_warning_no_vattype_at_all';
$code = 804;
} elseif (count($vatTypeInfo['union']) === 1) {
// One or more lines could be matched with exactly 1 vat
// type, but not all lines.
// Possible causes:
// - Non matching lines have no vat. Message: 'Manual line
// entered without vat' or 'Check vat settings on those
// products.'.
// - Non matching lines have vat. Message: 'Manual line
// entered with incorrect vat' or 'Check vat settings on
// those products.'.
$this->invoice[Tag::Customer][Tag::Invoice][Tag::VatType] = reset($vatTypeInfo['union']);
$message = 'message_warning_no_vattype_incorrect_lines';
$code = 812;
} else {
// Separate lines could be matched with some of the possible
// vat types, but not all with the same vat type.
// Possible causes:
// - Mix of foreign VAT rates and other goods or services.
// Message: 'Split invoice.'.
// - Some lines have no vat but no vat free goods or
// services are sold and thus this could be a reversed vat
// (company in EU) or vat free invoice (outside EU).
// Message: check vat settings.
// - Mix of margin scheme and normal vat: this can be solved
// by making it a margin scheme invoice and adding
// costprice = 0 to all normal lines.
if (in_array(Api::VatType_MarginScheme, $vatTypeInfo['union'])) {
$this->invoice[Tag::Customer][Tag::Invoice][Tag::VatType] = Api::VatType_MarginScheme;
} else {
// Take the first vat type as a guess but add a warning.
$this->invoice[Tag::Customer][Tag::Invoice][Tag::VatType] = reset($vatTypeInfo['union']);
$message = 'message_warning_no_vattype_must_split';
$code = 806;
}
}
} elseif (count($vatTypeInfo['intersection']) === 1) {
// Exactly 1 vat type was found to be possible for all lines:
// use that one as the vat type for the invoice.
$this->invoice[Tag::Customer][Tag::Invoice][Tag::VatType] = reset($vatTypeInfo['intersection']);
} else {
// Multiple vat types were found to be possible for all lines:
// Take one and add a warning.
// Possible causes:
// - Client country has same vat rates as the Netherlands and
// shop sells products at foreign vat rates but also other
// products or services. Solvable by correct shop settings.
// - Invoice has no vat and the client is outside the EU and it
// is unknown whether the invoice lines contain services or
// goods. Perhaps solvable by correct shop settings.
// - Margin invoice: all lines that have a costprice will
// probably also satisfy the normal vat. This is solvable by
// making it a margin scheme invoice and adding costprice = 0
// to all normal lines.
if (in_array(Api::VatType_MarginScheme, $vatTypeInfo['union'])) {
$this->invoice[Tag::Customer][Tag::Invoice][Tag::VatType] = Api::VatType_MarginScheme;
} else {
// Take the first vat type as a guess but add a warning.
$this->invoice[Tag::Customer][Tag::Invoice][Tag::VatType] = reset($vatTypeInfo['intersection']);
$message = 'message_warning_no_vattype_multiple_possible';
$code = 811;
}
}
if (!empty($message)) {
// Make the invoice a concept, so it can be changed in Acumulus
// and add message and meta info.
$startSentence = count($vatTypeInfo['intersection']) === 0
? 'message_warning_no_vattype'
: 'message_warning_multiple_vattypes';
$this->changeInvoiceToConcept($message, $code, $this->t($startSentence));
}
$this->invoice[Tag::Customer][Tag::Invoice][Meta::VatTypesPossibleInvoice] = implode(',', $this->possibleVatTypes);
$this->invoice[Tag::Customer][Tag::Invoice][Meta::VatTypesPossibleInvoiceLinesIntersection] = implode(',', $vatTypeInfo['intersection']);
$this->invoice[Tag::Customer][Tag::Invoice][Meta::VatTypesPossibleInvoiceLinesUnion] = implode(',', $vatTypeInfo['union']);
}
} | [
"protected",
"function",
"completeVatType",
"(",
")",
"{",
"// If shop specific code or an event handler has already set the vat",
"// type, we don't change it.",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"invoice",
"[",
"Tag",
"::",
"Customer",
"]",
"[",
"Tag",
"::",... | Determines the vattype of the invoice.
This method (and class) is aware of:
- The setting foreignVat.
- The country of the client.
- Whether the client is a company.
- The actual VAT rates on the day of the order.
- Whether there are margin products in the order.
So to start with, any list of (possible) vat types is based on the above.
Furthermore this method and {@see getInvoiceLinesVatTypeInfo()} are aware
of:
- The fact that orders do not have to be split over different vat types,
but that invoices should be split if both national and foreign VAT
rates appear on the order.
- The vat class meta data per line and which classes denote foreign vat.
This info is used to distinguish between NL and foreign vat for EU
countries that have VAT rates in common with NL and the settings
indicate that this shop sells products in both vat type categories.
If multiple vat types are possible, the invoice is sent as concept, so
that it may be corrected in Acumulus. | [
"Determines",
"the",
"vattype",
"of",
"the",
"invoice",
"."
] | 82f8d6c9c4929c41948c97d6cfdfac3f27c37255 | https://github.com/SIELOnline/libAcumulus/blob/82f8d6c9c4929c41948c97d6cfdfac3f27c37255/src/Invoice/Completor.php#L724-L832 | train |
SIELOnline/libAcumulus | src/Invoice/Completor.php | Completor.correctMarginInvoice | protected function correctMarginInvoice()
{
if (isset($this->invoice[Tag::Customer][Tag::Invoice][Tag::VatType]) && $this->invoice[Tag::Customer][Tag::Invoice][Tag::VatType] === Api::VatType_MarginScheme) {
foreach ($this->invoice[Tag::Customer][Tag::Invoice][Tag::Line] as &$line) {
// For margin invoices, Acumulus expects the unitprice to be the
// sales price, ie the price the client pays. So we set
// unitprice to unitpriceinc.
// Non margin lines may "officially" not appear on margin
// invoices, so we turn them into margin lines by adding a
// costprice of 0 and also setting unitprice to unitpriceinc.
if (!isset($line[Tag::CostPrice])) {
// "Normal" line: set costprice as 0.
$line[Tag::CostPrice] = 0.0;
}
// Add "marker" tag (for debug purposes) for this correction.
$line[Meta::RecalculateOldPrice] = $line[Tag::UnitPrice];
// Change unitprice tag to include VAT.
if (isset($line[Meta::UnitPriceInc])) {
$line[Tag::UnitPrice] = $line[Meta::UnitPriceInc];
} elseif (isset($line[Meta::VatAmount])) {
$line[Tag::UnitPrice] += $line[Meta::VatAmount];
} elseif (isset($line[Tag::VatRate])) {
$line[Tag::UnitPrice] += $line[Tag::VatRate]/100.0 * ($line[Tag::UnitPrice] - $line[Tag::CostPrice]);
} //else {
// Impossible to correct the unitprice. Probably all
// strategies failed, so the invoice should already
// have a warning.
//}
}
}
} | php | protected function correctMarginInvoice()
{
if (isset($this->invoice[Tag::Customer][Tag::Invoice][Tag::VatType]) && $this->invoice[Tag::Customer][Tag::Invoice][Tag::VatType] === Api::VatType_MarginScheme) {
foreach ($this->invoice[Tag::Customer][Tag::Invoice][Tag::Line] as &$line) {
// For margin invoices, Acumulus expects the unitprice to be the
// sales price, ie the price the client pays. So we set
// unitprice to unitpriceinc.
// Non margin lines may "officially" not appear on margin
// invoices, so we turn them into margin lines by adding a
// costprice of 0 and also setting unitprice to unitpriceinc.
if (!isset($line[Tag::CostPrice])) {
// "Normal" line: set costprice as 0.
$line[Tag::CostPrice] = 0.0;
}
// Add "marker" tag (for debug purposes) for this correction.
$line[Meta::RecalculateOldPrice] = $line[Tag::UnitPrice];
// Change unitprice tag to include VAT.
if (isset($line[Meta::UnitPriceInc])) {
$line[Tag::UnitPrice] = $line[Meta::UnitPriceInc];
} elseif (isset($line[Meta::VatAmount])) {
$line[Tag::UnitPrice] += $line[Meta::VatAmount];
} elseif (isset($line[Tag::VatRate])) {
$line[Tag::UnitPrice] += $line[Tag::VatRate]/100.0 * ($line[Tag::UnitPrice] - $line[Tag::CostPrice]);
} //else {
// Impossible to correct the unitprice. Probably all
// strategies failed, so the invoice should already
// have a warning.
//}
}
}
} | [
"protected",
"function",
"correctMarginInvoice",
"(",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"invoice",
"[",
"Tag",
"::",
"Customer",
"]",
"[",
"Tag",
"::",
"Invoice",
"]",
"[",
"Tag",
"::",
"VatType",
"]",
")",
"&&",
"$",
"this",
"->"... | Corrects an invoice if it is a margin scheme invoice.
If an invoice is of the margin scheme type, all lines have to follow the
margin scheme rules. These rules are:
- Each line must have a costprice, but that cost price may be 0.
- The unitprice should now contain the price including VAT (requirement
of the web service API).
Thus if there are e.g. shipping lines or other fee lines, they have to be
converted to the margin scheme (costprice tag and change of unitprice). | [
"Corrects",
"an",
"invoice",
"if",
"it",
"is",
"a",
"margin",
"scheme",
"invoice",
"."
] | 82f8d6c9c4929c41948c97d6cfdfac3f27c37255 | https://github.com/SIELOnline/libAcumulus/blob/82f8d6c9c4929c41948c97d6cfdfac3f27c37255/src/Invoice/Completor.php#L957-L987 | train |
SIELOnline/libAcumulus | src/Invoice/Completor.php | Completor.correct0VatToVatFree | protected function correct0VatToVatFree()
{
if (isset($this->invoice[Tag::Customer][Tag::Invoice][Tag::VatType])) {
$vatType = $this->invoice[Tag::Customer][Tag::Invoice][Tag::VatType];
if (in_array($vatType, static::$vatTypesAllowingVatFree)) {
foreach ($this->invoice[Tag::Customer][Tag::Invoice][Tag::Line] as &$line) {
if ($this->lineHas0VatRate($line)) {
$line[Tag::VatRate] = Api::VatFree;
}
}
}
}
} | php | protected function correct0VatToVatFree()
{
if (isset($this->invoice[Tag::Customer][Tag::Invoice][Tag::VatType])) {
$vatType = $this->invoice[Tag::Customer][Tag::Invoice][Tag::VatType];
if (in_array($vatType, static::$vatTypesAllowingVatFree)) {
foreach ($this->invoice[Tag::Customer][Tag::Invoice][Tag::Line] as &$line) {
if ($this->lineHas0VatRate($line)) {
$line[Tag::VatRate] = Api::VatFree;
}
}
}
}
} | [
"protected",
"function",
"correct0VatToVatFree",
"(",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"invoice",
"[",
"Tag",
"::",
"Customer",
"]",
"[",
"Tag",
"::",
"Invoice",
"]",
"[",
"Tag",
"::",
"VatType",
"]",
")",
")",
"{",
"$",
"vatType... | Change 0% vat rates to vat free.
Acumulus distinguishes between 0% vat (vatrate = 0) and vat free
(vatrate = -1).
0% vat should be used with:
- Reversed vat invoices, EU or national (vat type = 2 or 3).
- Products invoiced outside the EU (vat type = 4).
Vat free should be used for:
- Vat free products and services, e.g. care, education (vat type = 1, 5
or, theoretically, 6).
- Services invoiced to companies outside the EU (vat type = 1).
- Digital services outside the EU, consumers or companies (vat type = 1).
Thus, to do this correctly, especially for invoices outside the EU, we
should be able to distinguish between services and products. For that,
the nature field should be filled in or the shop should only sell
products or only services. If not, we act as if the line invoices a
product.
See:
- {@see https://www.belastingdienst.nl/wps/wcm/connect/bldcontentnl/belastingdienst/zakelijk/btw/tarieven_en_vrijstellingen/}
- {@see https://wiki.acumulus.nl/index.php?page=facturen-naar-het-buitenland}: | [
"Change",
"0%",
"vat",
"rates",
"to",
"vat",
"free",
"."
] | 82f8d6c9c4929c41948c97d6cfdfac3f27c37255 | https://github.com/SIELOnline/libAcumulus/blob/82f8d6c9c4929c41948c97d6cfdfac3f27c37255/src/Invoice/Completor.php#L1013-L1025 | train |
SIELOnline/libAcumulus | src/Invoice/Completor.php | Completor.processMetaData | protected function processMetaData()
{
foreach ($this->invoice[Tag::Customer][Tag::Invoice][Tag::Line] as &$line) {
if (isset($line[Meta::VatRateLookup]) && is_array($line[Meta::VatRateLookup])) {
$line[Meta::VatRateLookup] = json_encode($line[Meta::VatRateLookup]);
}
if (isset($line[Meta::VatRateLookupLabel]) && is_array($line[Meta::VatRateLookupLabel])) {
$line[Meta::VatRateLookupLabel] = json_encode($line[Meta::VatRateLookupLabel]);
}
if (isset($line[Meta::FieldsCalculated]) && is_array($line[Meta::FieldsCalculated])) {
$line[Meta::FieldsCalculated] = json_encode(array_unique($line[Meta::FieldsCalculated]));
}
if (isset($line[Meta::VatRateLookupMatches]) && is_array($line[Meta::VatRateLookupMatches])) {
$line[Meta::VatRateLookupMatches] = json_encode($line[Meta::VatRateLookupMatches]);
}
if (isset($line[Meta::VatRateRangeMatches]) && is_array($line[Meta::VatRateRangeMatches])) {
$line[Meta::VatRateRangeMatches] = json_encode($line[Meta::VatRateRangeMatches]);
}
}
} | php | protected function processMetaData()
{
foreach ($this->invoice[Tag::Customer][Tag::Invoice][Tag::Line] as &$line) {
if (isset($line[Meta::VatRateLookup]) && is_array($line[Meta::VatRateLookup])) {
$line[Meta::VatRateLookup] = json_encode($line[Meta::VatRateLookup]);
}
if (isset($line[Meta::VatRateLookupLabel]) && is_array($line[Meta::VatRateLookupLabel])) {
$line[Meta::VatRateLookupLabel] = json_encode($line[Meta::VatRateLookupLabel]);
}
if (isset($line[Meta::FieldsCalculated]) && is_array($line[Meta::FieldsCalculated])) {
$line[Meta::FieldsCalculated] = json_encode(array_unique($line[Meta::FieldsCalculated]));
}
if (isset($line[Meta::VatRateLookupMatches]) && is_array($line[Meta::VatRateLookupMatches])) {
$line[Meta::VatRateLookupMatches] = json_encode($line[Meta::VatRateLookupMatches]);
}
if (isset($line[Meta::VatRateRangeMatches]) && is_array($line[Meta::VatRateRangeMatches])) {
$line[Meta::VatRateRangeMatches] = json_encode($line[Meta::VatRateRangeMatches]);
}
}
} | [
"protected",
"function",
"processMetaData",
"(",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"invoice",
"[",
"Tag",
"::",
"Customer",
"]",
"[",
"Tag",
"::",
"Invoice",
"]",
"[",
"Tag",
"::",
"Line",
"]",
"as",
"&",
"$",
"line",
")",
"{",
"if",
"("... | Processes meta data before sending the invoice.
Currently the following processing is done:
- Meta::VatRateLookup, Meta::VatRateLookupLabel, Meta::FieldsCalculated,
Meta::VatRateLookupMatches, and Meta::VatRateRangeMatches are converted
a json string if they are an array. | [
"Processes",
"meta",
"data",
"before",
"sending",
"the",
"invoice",
"."
] | 82f8d6c9c4929c41948c97d6cfdfac3f27c37255 | https://github.com/SIELOnline/libAcumulus/blob/82f8d6c9c4929c41948c97d6cfdfac3f27c37255/src/Invoice/Completor.php#L1049-L1068 | train |
SIELOnline/libAcumulus | src/Invoice/Completor.php | Completor.lineHas0VatRate | protected function lineHas0VatRate(array $line)
{
$result = false;
if ($this->is0VatRate($line)) {
$result = true;
}
return $result;
} | php | protected function lineHas0VatRate(array $line)
{
$result = false;
if ($this->is0VatRate($line)) {
$result = true;
}
return $result;
} | [
"protected",
"function",
"lineHas0VatRate",
"(",
"array",
"$",
"line",
")",
"{",
"$",
"result",
"=",
"false",
";",
"if",
"(",
"$",
"this",
"->",
"is0VatRate",
"(",
"$",
"line",
")",
")",
"{",
"$",
"result",
"=",
"true",
";",
"}",
"return",
"$",
"re... | Returns whether the given line has a 0% or vat free vat rate.
@param array $line
The invoice line.
@return bool
True if the given line has a 0% or vat free vat rate, false otherwise. | [
"Returns",
"whether",
"the",
"given",
"line",
"has",
"a",
"0%",
"or",
"vat",
"free",
"vat",
"rate",
"."
] | 82f8d6c9c4929c41948c97d6cfdfac3f27c37255 | https://github.com/SIELOnline/libAcumulus/blob/82f8d6c9c4929c41948c97d6cfdfac3f27c37255/src/Invoice/Completor.php#L1079-L1086 | train |
SIELOnline/libAcumulus | src/Invoice/Completor.php | Completor.is0VatRate | protected function is0VatRate($vatRate)
{
if (is_array($vatRate) && isset($vatRate)) {
$vatRate = isset($vatRate[Tag::VatRate]) ? $vatRate[Tag::VatRate] : null;
}
return isset($vatRate) && (Number::isZero($vatRate) || Number::floatsAreEqual($vatRate, -1.0));
} | php | protected function is0VatRate($vatRate)
{
if (is_array($vatRate) && isset($vatRate)) {
$vatRate = isset($vatRate[Tag::VatRate]) ? $vatRate[Tag::VatRate] : null;
}
return isset($vatRate) && (Number::isZero($vatRate) || Number::floatsAreEqual($vatRate, -1.0));
} | [
"protected",
"function",
"is0VatRate",
"(",
"$",
"vatRate",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"vatRate",
")",
"&&",
"isset",
"(",
"$",
"vatRate",
")",
")",
"{",
"$",
"vatRate",
"=",
"isset",
"(",
"$",
"vatRate",
"[",
"Tag",
"::",
"VatRate",
... | Returns whether the vat rate is a 0 vat rate.
@param int|array $vatRate
An integer (or numeric string), an array possibly containing an entry
with key Tag::VatRate entry
@return bool
True if the vat rate is a 0 vat rate, false otherwise. | [
"Returns",
"whether",
"the",
"vat",
"rate",
"is",
"a",
"0",
"vat",
"rate",
"."
] | 82f8d6c9c4929c41948c97d6cfdfac3f27c37255 | https://github.com/SIELOnline/libAcumulus/blob/82f8d6c9c4929c41948c97d6cfdfac3f27c37255/src/Invoice/Completor.php#L1117-L1123 | train |
SIELOnline/libAcumulus | src/Invoice/Completor.php | Completor.getVatRatesByCountryAndDate | protected function getVatRatesByCountryAndDate($countryCode, $date = null)
{
if (empty($date)) {
$date = $this->getInvoiceDate();
}
$result = $this->service->getVatInfo($countryCode, $date);
if ($result->hasMessages()) {
$this->result->mergeMessages($result);
}
$vatInfo = $result->getResponse();
// PHP5.5: array_column($vatInfo, Tag::VatRate);
$vatInfo = array_unique(array_map(function ($vatInfo1) {
return $vatInfo1[Tag::VatRate];
}, $vatInfo));
return $vatInfo;
} | php | protected function getVatRatesByCountryAndDate($countryCode, $date = null)
{
if (empty($date)) {
$date = $this->getInvoiceDate();
}
$result = $this->service->getVatInfo($countryCode, $date);
if ($result->hasMessages()) {
$this->result->mergeMessages($result);
}
$vatInfo = $result->getResponse();
// PHP5.5: array_column($vatInfo, Tag::VatRate);
$vatInfo = array_unique(array_map(function ($vatInfo1) {
return $vatInfo1[Tag::VatRate];
}, $vatInfo));
return $vatInfo;
} | [
"protected",
"function",
"getVatRatesByCountryAndDate",
"(",
"$",
"countryCode",
",",
"$",
"date",
"=",
"null",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"date",
")",
")",
"{",
"$",
"date",
"=",
"$",
"this",
"->",
"getInvoiceDate",
"(",
")",
";",
"}",
... | Helper method to get the vat rates for the current invoice.
- This method contacts the Acumulus server.
- The vat rates returned reflect those as they were at the invoice date.
- No zero vat rates are returned.
@param string $countryCode
The country to fetch the vat rates for.
@param string|null $date
The date (yyyy-mm-dd) to fetch the vat rates for.
@return float[]
Actual type will be string[] containing strings representing floats.
@see \Siel\Acumulus\Web\Service::getVatInfo(). | [
"Helper",
"method",
"to",
"get",
"the",
"vat",
"rates",
"for",
"the",
"current",
"invoice",
"."
] | 82f8d6c9c4929c41948c97d6cfdfac3f27c37255 | https://github.com/SIELOnline/libAcumulus/blob/82f8d6c9c4929c41948c97d6cfdfac3f27c37255/src/Invoice/Completor.php#L1142-L1157 | train |
SIELOnline/libAcumulus | src/Invoice/Completor.php | Completor.getInvoiceDate | protected function getInvoiceDate()
{
$date = !empty($this->invoice[Tag::Customer][Tag::Invoice][Tag::IssueDate]) ? $this->invoice[Tag::Customer][Tag::Invoice][Tag::IssueDate] : date(API::DateFormat_Iso);
return $date;
} | php | protected function getInvoiceDate()
{
$date = !empty($this->invoice[Tag::Customer][Tag::Invoice][Tag::IssueDate]) ? $this->invoice[Tag::Customer][Tag::Invoice][Tag::IssueDate] : date(API::DateFormat_Iso);
return $date;
} | [
"protected",
"function",
"getInvoiceDate",
"(",
")",
"{",
"$",
"date",
"=",
"!",
"empty",
"(",
"$",
"this",
"->",
"invoice",
"[",
"Tag",
"::",
"Customer",
"]",
"[",
"Tag",
"::",
"Invoice",
"]",
"[",
"Tag",
"::",
"IssueDate",
"]",
")",
"?",
"$",
"th... | Returns the invoice date in the iso yyyy-mm-dd format.
@return string
The invoice dae in the iso yyyy-mm-dd format. | [
"Returns",
"the",
"invoice",
"date",
"in",
"the",
"iso",
"yyyy",
"-",
"mm",
"-",
"dd",
"format",
"."
] | 82f8d6c9c4929c41948c97d6cfdfac3f27c37255 | https://github.com/SIELOnline/libAcumulus/blob/82f8d6c9c4929c41948c97d6cfdfac3f27c37255/src/Invoice/Completor.php#L1165-L1169 | train |
SIELOnline/libAcumulus | src/Invoice/Completor.php | Completor.isCompany | protected function isCompany()
{
// Note: companies outside EU must also fill in their vat number!? Even
// if there's no way to check it with a webservice like VIES.
return !empty($this->invoice[Tag::Customer][Tag::CompanyName1]) && !empty($this->invoice[Tag::Customer][Tag::VatNumber]);
} | php | protected function isCompany()
{
// Note: companies outside EU must also fill in their vat number!? Even
// if there's no way to check it with a webservice like VIES.
return !empty($this->invoice[Tag::Customer][Tag::CompanyName1]) && !empty($this->invoice[Tag::Customer][Tag::VatNumber]);
} | [
"protected",
"function",
"isCompany",
"(",
")",
"{",
"// Note: companies outside EU must also fill in their vat number!? Even",
"// if there's no way to check it with a webservice like VIES.",
"return",
"!",
"empty",
"(",
"$",
"this",
"->",
"invoice",
"[",
"Tag",
"::",
"Custome... | Returns whether the client is a company with a vat number.
@return bool | [
"Returns",
"whether",
"the",
"client",
"is",
"a",
"company",
"with",
"a",
"vat",
"number",
"."
] | 82f8d6c9c4929c41948c97d6cfdfac3f27c37255 | https://github.com/SIELOnline/libAcumulus/blob/82f8d6c9c4929c41948c97d6cfdfac3f27c37255/src/Invoice/Completor.php#L1206-L1211 | train |
SIELOnline/libAcumulus | src/Invoice/Completor.php | Completor.shouldConvertCurrency | public function shouldConvertCurrency(array &$invoice)
{
$invoicePart = &$invoice[Tag::Customer][Tag::Invoice];
$shouldConvert = isset($invoicePart[Meta::Currency]) && isset($invoicePart[Meta::CurrencyRate]) && isset($invoicePart[Meta::CurrencyDoConvert]);
$shouldConvert = $shouldConvert && (float) $invoicePart[Meta::CurrencyRate] != 1.0;
if ($shouldConvert) {
if ($invoicePart[Meta::Currency] !== 'EUR') {
// Order/refund is not in euro's: convert if amounts are stored
// in the order's currency, not the shop's default currency
// (which should be EUR).
$shouldConvert = $invoicePart[Meta::CurrencyDoConvert];
$invoicePart[Meta::CurrencyRateInverted] = false;
} else {
// Order/refund is in euro's but that is not the shop's default:
// convert if the amounts are in the in the shop's default
// currency, not the order's currency (which is EUR).
$shouldConvert = !$invoicePart[Meta::CurrencyDoConvert];
// Invert the rate only once, even if this method may be called
// multiple times per invoice.
if (!isset($invoicePart[Meta::CurrencyRateInverted])) {
$invoicePart[Meta::CurrencyRateInverted] = true;
$invoicePart[Meta::CurrencyRate] = 1.0 / (float) $invoicePart[Meta::CurrencyRate];
}
}
}
return $shouldConvert;
} | php | public function shouldConvertCurrency(array &$invoice)
{
$invoicePart = &$invoice[Tag::Customer][Tag::Invoice];
$shouldConvert = isset($invoicePart[Meta::Currency]) && isset($invoicePart[Meta::CurrencyRate]) && isset($invoicePart[Meta::CurrencyDoConvert]);
$shouldConvert = $shouldConvert && (float) $invoicePart[Meta::CurrencyRate] != 1.0;
if ($shouldConvert) {
if ($invoicePart[Meta::Currency] !== 'EUR') {
// Order/refund is not in euro's: convert if amounts are stored
// in the order's currency, not the shop's default currency
// (which should be EUR).
$shouldConvert = $invoicePart[Meta::CurrencyDoConvert];
$invoicePart[Meta::CurrencyRateInverted] = false;
} else {
// Order/refund is in euro's but that is not the shop's default:
// convert if the amounts are in the in the shop's default
// currency, not the order's currency (which is EUR).
$shouldConvert = !$invoicePart[Meta::CurrencyDoConvert];
// Invert the rate only once, even if this method may be called
// multiple times per invoice.
if (!isset($invoicePart[Meta::CurrencyRateInverted])) {
$invoicePart[Meta::CurrencyRateInverted] = true;
$invoicePart[Meta::CurrencyRate] = 1.0 / (float) $invoicePart[Meta::CurrencyRate];
}
}
}
return $shouldConvert;
} | [
"public",
"function",
"shouldConvertCurrency",
"(",
"array",
"&",
"$",
"invoice",
")",
"{",
"$",
"invoicePart",
"=",
"&",
"$",
"invoice",
"[",
"Tag",
"::",
"Customer",
"]",
"[",
"Tag",
"::",
"Invoice",
"]",
";",
"$",
"shouldConvert",
"=",
"isset",
"(",
... | Returns whether the amounts in the invoice are in another currency.
The amounts in te invoice are to be converted if:
- All currency meta tags are set.
- The "currency rate" does not equal 1.0, otherwise converting would
result in the same amounts.
- The meta tag "do convert" equals "currency !== 'EUR'.
@param array $invoice
The invoice (starting with the customer part).
@return bool
True if the invoice uses another currency, false otherwise. | [
"Returns",
"whether",
"the",
"amounts",
"in",
"the",
"invoice",
"are",
"in",
"another",
"currency",
"."
] | 82f8d6c9c4929c41948c97d6cfdfac3f27c37255 | https://github.com/SIELOnline/libAcumulus/blob/82f8d6c9c4929c41948c97d6cfdfac3f27c37255/src/Invoice/Completor.php#L1228-L1254 | train |
SIELOnline/libAcumulus | src/Invoice/Completor.php | Completor.convertAmount | public function convertAmount(array &$array, $key, $conversionRate)
{
if (!empty($array[$key]) && !empty($conversionRate)) {
$array[$key] = (float) $array[$key] / (float) $conversionRate;
return true;
}
return false;
} | php | public function convertAmount(array &$array, $key, $conversionRate)
{
if (!empty($array[$key]) && !empty($conversionRate)) {
$array[$key] = (float) $array[$key] / (float) $conversionRate;
return true;
}
return false;
} | [
"public",
"function",
"convertAmount",
"(",
"array",
"&",
"$",
"array",
",",
"$",
"key",
",",
"$",
"conversionRate",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"array",
"[",
"$",
"key",
"]",
")",
"&&",
"!",
"empty",
"(",
"$",
"conversionRate",
")... | Helper method to convert an amount field to euros.
@param array $array
@param string $key
@param float $conversionRate
@return bool
Whether the amount was converted. | [
"Helper",
"method",
"to",
"convert",
"an",
"amount",
"field",
"to",
"euros",
"."
] | 82f8d6c9c4929c41948c97d6cfdfac3f27c37255 | https://github.com/SIELOnline/libAcumulus/blob/82f8d6c9c4929c41948c97d6cfdfac3f27c37255/src/Invoice/Completor.php#L1266-L1273 | train |
SIELOnline/libAcumulus | src/Invoice/Completor.php | Completor.isForeignVatClass | public function isForeignVatClass($vatClassId)
{
$shopSettings = $this->config->getShopSettings();
$foreignVat = $shopSettings['foreignVat'];
$foreignVatClasses = $shopSettings['foreignVatClasses'];
return $foreignVat !== PluginConfig::ForeignVat_No && in_array($vatClassId, $foreignVatClasses);
} | php | public function isForeignVatClass($vatClassId)
{
$shopSettings = $this->config->getShopSettings();
$foreignVat = $shopSettings['foreignVat'];
$foreignVatClasses = $shopSettings['foreignVatClasses'];
return $foreignVat !== PluginConfig::ForeignVat_No && in_array($vatClassId, $foreignVatClasses);
} | [
"public",
"function",
"isForeignVatClass",
"(",
"$",
"vatClassId",
")",
"{",
"$",
"shopSettings",
"=",
"$",
"this",
"->",
"config",
"->",
"getShopSettings",
"(",
")",
";",
"$",
"foreignVat",
"=",
"$",
"shopSettings",
"[",
"'foreignVat'",
"]",
";",
"$",
"fo... | Returns whether the vat class id denotes foreign vat.
@param int|string $vatClassId
The vat class to check.
@return bool
True if the shop might sell foreign vat articles and the vat class id
denotes a foreign vat class, false otherwise. | [
"Returns",
"whether",
"the",
"vat",
"class",
"id",
"denotes",
"foreign",
"vat",
"."
] | 82f8d6c9c4929c41948c97d6cfdfac3f27c37255 | https://github.com/SIELOnline/libAcumulus/blob/82f8d6c9c4929c41948c97d6cfdfac3f27c37255/src/Invoice/Completor.php#L1301-L1307 | train |
SIELOnline/libAcumulus | src/Invoice/Completor.php | Completor.changeInvoiceToConcept | public function changeInvoiceToConcept($messageKey, $code)
{
$pdfMessage = '';
$invoiceSettings = $this->config->getInvoiceSettings();
$concept = $invoiceSettings['concept'];
if ($concept == PluginConfig::Concept_Plugin) {
$this->invoice[Tag::Customer][Tag::Invoice][Tag::Concept] = Api::Concept_Yes;
$emailAsPdfSettings = $this->config->getEmailAsPdfSettings();
if ($emailAsPdfSettings['emailAsPdf']) {
$pdfMessage = ' ' . $this->t('message_warning_no_pdf');
}
}
if ($messageKey !== '') {
$message = $this->t($messageKey) . $pdfMessage;
if (func_num_args() > 2) {
$args = func_get_args();
$message = vsprintf($message, array_slice($args, 2));
}
$this->result->addWarning($code, '', $message);
}
} | php | public function changeInvoiceToConcept($messageKey, $code)
{
$pdfMessage = '';
$invoiceSettings = $this->config->getInvoiceSettings();
$concept = $invoiceSettings['concept'];
if ($concept == PluginConfig::Concept_Plugin) {
$this->invoice[Tag::Customer][Tag::Invoice][Tag::Concept] = Api::Concept_Yes;
$emailAsPdfSettings = $this->config->getEmailAsPdfSettings();
if ($emailAsPdfSettings['emailAsPdf']) {
$pdfMessage = ' ' . $this->t('message_warning_no_pdf');
}
}
if ($messageKey !== '') {
$message = $this->t($messageKey) . $pdfMessage;
if (func_num_args() > 2) {
$args = func_get_args();
$message = vsprintf($message, array_slice($args, 2));
}
$this->result->addWarning($code, '', $message);
}
} | [
"public",
"function",
"changeInvoiceToConcept",
"(",
"$",
"messageKey",
",",
"$",
"code",
")",
"{",
"$",
"pdfMessage",
"=",
"''",
";",
"$",
"invoiceSettings",
"=",
"$",
"this",
"->",
"config",
"->",
"getInvoiceSettings",
"(",
")",
";",
"$",
"concept",
"=",... | Makes the invoice a concept invoice and optionally adds a warning.
@param string $messageKey
The key of the message to add as warning, or the empty string if no
warning has to be added.
@param int $code
The code for this message.
@param string ...
Additional arguments to format the message. | [
"Makes",
"the",
"invoice",
"a",
"concept",
"invoice",
"and",
"optionally",
"adds",
"a",
"warning",
"."
] | 82f8d6c9c4929c41948c97d6cfdfac3f27c37255 | https://github.com/SIELOnline/libAcumulus/blob/82f8d6c9c4929c41948c97d6cfdfac3f27c37255/src/Invoice/Completor.php#L1320-L1341 | train |
SIELOnline/libAcumulus | src/Invoice/Completor.php | Completor.addDefault | protected function addDefault(array &$array, $key, $value)
{
if (empty($array[$key]) && !empty($value)) {
$array[$key] = $value;
return true;
}
return false;
} | php | protected function addDefault(array &$array, $key, $value)
{
if (empty($array[$key]) && !empty($value)) {
$array[$key] = $value;
return true;
}
return false;
} | [
"protected",
"function",
"addDefault",
"(",
"array",
"&",
"$",
"array",
",",
"$",
"key",
",",
"$",
"value",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"array",
"[",
"$",
"key",
"]",
")",
"&&",
"!",
"empty",
"(",
"$",
"value",
")",
")",
"{",
"$",
... | Helper method to add a default non-empty value to an array.
This method will not overwrite existing values.
@param array $array
@param string $key
@param mixed $value
@return bool
Whether the default was added. | [
"Helper",
"method",
"to",
"add",
"a",
"default",
"non",
"-",
"empty",
"value",
"to",
"an",
"array",
"."
] | 82f8d6c9c4929c41948c97d6cfdfac3f27c37255 | https://github.com/SIELOnline/libAcumulus/blob/82f8d6c9c4929c41948c97d6cfdfac3f27c37255/src/Invoice/Completor.php#L1355-L1362 | train |
SIELOnline/libAcumulus | src/Web/Service.php | Service.getVatInfo | public function getVatInfo($countryCode, $date = '')
{
if (empty($date)) {
$date = date(API::DateFormat_Iso);
}
$message = array(
'vatdate' => $date,
'vatcountry' => $countryCode,
);
return $this->communicator->callApiFunction('lookups/lookup_vatinfo', $message)->setMainResponseKey('vatinfo', true);
} | php | public function getVatInfo($countryCode, $date = '')
{
if (empty($date)) {
$date = date(API::DateFormat_Iso);
}
$message = array(
'vatdate' => $date,
'vatcountry' => $countryCode,
);
return $this->communicator->callApiFunction('lookups/lookup_vatinfo', $message)->setMainResponseKey('vatinfo', true);
} | [
"public",
"function",
"getVatInfo",
"(",
"$",
"countryCode",
",",
"$",
"date",
"=",
"''",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"date",
")",
")",
"{",
"$",
"date",
"=",
"date",
"(",
"API",
"::",
"DateFormat_Iso",
")",
";",
"}",
"$",
"message",
... | Retrieves a list of VAT rates for the given country at the given date.
@param string $countryCode
Country code of the country to retrieve the VAT info for.
@param string $date
ISO date string (yyyy-mm-dd) for the date to retrieve the VAT info for.
@return \Siel\Acumulus\Web\Result
The result of the webservice call. The structured response will contain
a non-keyed array of "vatinfo" arrays, each 'vatinfo' array being a
keyed array with keys:
- vattype
- vatrate
@see https://www.siel.nl/acumulus/API/Picklists/VAT_Info/
for more information about the contents of the returned array. | [
"Retrieves",
"a",
"list",
"of",
"VAT",
"rates",
"for",
"the",
"given",
"country",
"at",
"the",
"given",
"date",
"."
] | 82f8d6c9c4929c41948c97d6cfdfac3f27c37255 | https://github.com/SIELOnline/libAcumulus/blob/82f8d6c9c4929c41948c97d6cfdfac3f27c37255/src/Web/Service.php#L241-L251 | train |
SIELOnline/libAcumulus | src/Web/Service.php | Service.invoiceAdd | public function invoiceAdd(array $invoice, Result $result = null)
{
return $this->communicator->callApiFunction('invoices/invoice_add', $invoice, $result)->setMainResponseKey('invoice');
} | php | public function invoiceAdd(array $invoice, Result $result = null)
{
return $this->communicator->callApiFunction('invoices/invoice_add', $invoice, $result)->setMainResponseKey('invoice');
} | [
"public",
"function",
"invoiceAdd",
"(",
"array",
"$",
"invoice",
",",
"Result",
"$",
"result",
"=",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"communicator",
"->",
"callApiFunction",
"(",
"'invoices/invoice_add'",
",",
"$",
"invoice",
",",
"$",
"result... | Sends an invoice to Acumulus.
@param array $invoice
The invoice to send.
@param \Siel\Acumulus\Web\Result|null $result
It is possible to already create a Result object before calling the Web
Service to store local messages. By passing this Result object these
local messages will be merged with any remote messages in the returned
Result object.
@return \Siel\Acumulus\Web\Result
The Result of the webservice call. A successful call will contain a
response array with key:
- invoice: an array of information about the created invoice, being an
array with keys:
- invoicenumber
- token
- entryid
@see https://www.siel.nl/acumulus/API/Invoicing/Add_Invoice/ | [
"Sends",
"an",
"invoice",
"to",
"Acumulus",
"."
] | 82f8d6c9c4929c41948c97d6cfdfac3f27c37255 | https://github.com/SIELOnline/libAcumulus/blob/82f8d6c9c4929c41948c97d6cfdfac3f27c37255/src/Web/Service.php#L275-L278 | train |
SIELOnline/libAcumulus | src/Web/Service.php | Service.setDeleteStatus | public function setDeleteStatus($entryId, $deleteStatus)
{
$message = array(
'entryid' => (int) $entryId,
'entrydeletestatus' => (int) $deleteStatus,
);
// @todo: clean up on receiving P2XFELO12?
return $this->communicator->callApiFunction('entry/entry_deletestatus_set', $message)->setMainResponseKey('entry');
} | php | public function setDeleteStatus($entryId, $deleteStatus)
{
$message = array(
'entryid' => (int) $entryId,
'entrydeletestatus' => (int) $deleteStatus,
);
// @todo: clean up on receiving P2XFELO12?
return $this->communicator->callApiFunction('entry/entry_deletestatus_set', $message)->setMainResponseKey('entry');
} | [
"public",
"function",
"setDeleteStatus",
"(",
"$",
"entryId",
",",
"$",
"deleteStatus",
")",
"{",
"$",
"message",
"=",
"array",
"(",
"'entryid'",
"=>",
"(",
"int",
")",
"$",
"entryId",
",",
"'entrydeletestatus'",
"=>",
"(",
"int",
")",
"$",
"deleteStatus",... | Moves the entry into or out of the trashbin.
@param int $entryId
The id of the entry.
@param int $deleteStatus
The delete action to perform: one of the API::Entry_Delete or
API::Entry_UnDelete constants. API::Entry_UnDelete does not work for
now.
@return \Siel\Acumulus\Web\Result
The result of the webservice call. The structured response will contain
1 "entry" array, being a keyed array with keys:
- entryid
- entryproc: (description new status): 'removed' or '???'
Possible errors:
- "XCM7ELO12: Invalid entrydeletestatus value supplied": $deleteStatus
is not one of the indicated constants.
- "XCM7ELO14: Invalid entrydeletestatus value supplied": $deleteStatus
is not one of the indicated constants.
- "P2XFELO12: Requested for entryid: $entryId not found or forbidden":
$entryId does not exist or already has requested status.
@see https://siel.nl/acumulus/API/Entry/Set_Delete_Status/ | [
"Moves",
"the",
"entry",
"into",
"or",
"out",
"of",
"the",
"trashbin",
"."
] | 82f8d6c9c4929c41948c97d6cfdfac3f27c37255 | https://github.com/SIELOnline/libAcumulus/blob/82f8d6c9c4929c41948c97d6cfdfac3f27c37255/src/Web/Service.php#L353-L361 | train |
SIELOnline/libAcumulus | src/Web/Service.php | Service.getPaymentStatus | public function getPaymentStatus($token)
{
$message = array(
'token' => (string) $token,
);
return $this->communicator->callApiFunction('invoices/invoice_paymentstatus_get', $message)->setMainResponseKey('invoice');
} | php | public function getPaymentStatus($token)
{
$message = array(
'token' => (string) $token,
);
return $this->communicator->callApiFunction('invoices/invoice_paymentstatus_get', $message)->setMainResponseKey('invoice');
} | [
"public",
"function",
"getPaymentStatus",
"(",
"$",
"token",
")",
"{",
"$",
"message",
"=",
"array",
"(",
"'token'",
"=>",
"(",
"string",
")",
"$",
"token",
",",
")",
";",
"return",
"$",
"this",
"->",
"communicator",
"->",
"callApiFunction",
"(",
"'invoi... | Retrieves the payment status for an invoice.
@param string $token
The token for the invoice.
@return \Siel\Acumulus\Web\Result
The result of the webservice call. The structured response will contain
1 "invoice" array, being a keyed array with keys:
- entryid
- token
- paymentstatus
- paymentdate
Possible errors:
- "XGYTTNF04: Requested invoice for $token not found": $token does not
exist.
@see https://www.siel.nl/acumulus/API/Invoicing/Payment_Get_Status/ | [
"Retrieves",
"the",
"payment",
"status",
"for",
"an",
"invoice",
"."
] | 82f8d6c9c4929c41948c97d6cfdfac3f27c37255 | https://github.com/SIELOnline/libAcumulus/blob/82f8d6c9c4929c41948c97d6cfdfac3f27c37255/src/Web/Service.php#L382-L388 | train |
SIELOnline/libAcumulus | src/Web/Service.php | Service.setPaymentStatus | public function setPaymentStatus($token, $paymentStatus, $paymentDate = '')
{
if (empty($paymentDate)) {
$paymentDate = date(API::DateFormat_Iso);
}
$message = array(
'token' => (string) $token,
'paymentstatus' => (int) $paymentStatus,
'paymentdate' => (string) $paymentDate,
);
return $this->communicator->callApiFunction('invoices/invoice_paymentstatus_set', $message)->setMainResponseKey('invoice');
} | php | public function setPaymentStatus($token, $paymentStatus, $paymentDate = '')
{
if (empty($paymentDate)) {
$paymentDate = date(API::DateFormat_Iso);
}
$message = array(
'token' => (string) $token,
'paymentstatus' => (int) $paymentStatus,
'paymentdate' => (string) $paymentDate,
);
return $this->communicator->callApiFunction('invoices/invoice_paymentstatus_set', $message)->setMainResponseKey('invoice');
} | [
"public",
"function",
"setPaymentStatus",
"(",
"$",
"token",
",",
"$",
"paymentStatus",
",",
"$",
"paymentDate",
"=",
"''",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"paymentDate",
")",
")",
"{",
"$",
"paymentDate",
"=",
"date",
"(",
"API",
"::",
"DateFo... | Sets the payment status for an invoice.
@param string $token
The token for the invoice.
@param int $paymentStatus
The new payment status, 1 of the API::PaymentStatus_Paid or
API::PaymentStatus_Due constants.
@param string $paymentDate
ISO date string (yyyy-mm-dd) for the date to set as payment date, may
be empty for today or if the payment sattus is API::PaymentStatus_Due.
@return \Siel\Acumulus\Web\Result
The result of the webservice call. The structured response will contain
1 "invoice" array, being a keyed array with keys:
- entryid
- token
- paymentstatus
- paymentdate
Possible errors:
- "DATE590ZW: Missing mandatory paymentdate field. Unable to proceed."
- "DATE590ZW: Incorrect date range (2000-01-01 to 2099-12-31) or
invalid date format (YYYY-MM-DD) used in paymentdate field. We
received: $paymentDate. Unable to proceed."
@see https://www.siel.nl/acumulus/API/Invoicing/Payment_Set_Status/ | [
"Sets",
"the",
"payment",
"status",
"for",
"an",
"invoice",
"."
] | 82f8d6c9c4929c41948c97d6cfdfac3f27c37255 | https://github.com/SIELOnline/libAcumulus/blob/82f8d6c9c4929c41948c97d6cfdfac3f27c37255/src/Web/Service.php#L417-L428 | train |
SIELOnline/libAcumulus | src/Web/Service.php | Service.emailInvoiceAsPdf | public function emailInvoiceAsPdf($token, $invoiceType, array $emailAsPdf, $invoiceNotes = '')
{
$message = array(
'token' => (string) $token,
'invoicetype' => (int) $invoiceType,
'emailaspdf' => $emailAsPdf,
);
if (!empty($invoiceNotes)) {
$message['invoicenotes'] = (string) $invoiceNotes;
}
return $this->communicator->callApiFunction('invoices/invoice_mail', $message)->setMainResponseKey('invoice');
} | php | public function emailInvoiceAsPdf($token, $invoiceType, array $emailAsPdf, $invoiceNotes = '')
{
$message = array(
'token' => (string) $token,
'invoicetype' => (int) $invoiceType,
'emailaspdf' => $emailAsPdf,
);
if (!empty($invoiceNotes)) {
$message['invoicenotes'] = (string) $invoiceNotes;
}
return $this->communicator->callApiFunction('invoices/invoice_mail', $message)->setMainResponseKey('invoice');
} | [
"public",
"function",
"emailInvoiceAsPdf",
"(",
"$",
"token",
",",
"$",
"invoiceType",
",",
"array",
"$",
"emailAsPdf",
",",
"$",
"invoiceNotes",
"=",
"''",
")",
"{",
"$",
"message",
"=",
"array",
"(",
"'token'",
"=>",
"(",
"string",
")",
"$",
"token",
... | Sends out an invoice or reminder as PDF.
@param string $token
The token for the invoice.
@param int $invoiceType
One of the constants API::Email_Normal or API::Email_Reminder.
@param array $emailAsPdf
An array with the fields:
- emailto
- emailbcc
- emailfrom
- subject
- message
- confirmreading
@param string $invoiceNotes
Multiline field for additional remarks. Use \n for newlines and \t for
tabs. Contents is placed in notes/comments section of the invoice.
Content will not appear on the actual invoice or associated emails.
@return \Siel\Acumulus\Web\Result
The result of the webservice call. The structured response will contain
1 "invoice" array, being a keyed array with keys:
- token
- invoicetype
Possible errors/warnings:
- "GK6FKHU52: Incorrect invoicetype value used (9) in invoicetype tag
as part of invoice section in the XML. Using default value of 0
normal."
- "TNFE4035G: Requested token not found or invalid token supplied.
Unable to proceed."
@see https://siel.nl/acumulus/API/Invoicing/Email/ | [
"Sends",
"out",
"an",
"invoice",
"or",
"reminder",
"as",
"PDF",
"."
] | 82f8d6c9c4929c41948c97d6cfdfac3f27c37255 | https://github.com/SIELOnline/libAcumulus/blob/82f8d6c9c4929c41948c97d6cfdfac3f27c37255/src/Web/Service.php#L464-L475 | train |
SIELOnline/libAcumulus | src/Web/Service.php | Service.getInvoicePdfUri | public function getInvoicePdfUri($token, $applyGraphics = true)
{
$uri = $this->communicator->getUri('invoices/invoice_get_pdf');
$uri .= "?token=$token";
if (!$applyGraphics) {
$uri .= '&gfx=0';
}
return $uri;
} | php | public function getInvoicePdfUri($token, $applyGraphics = true)
{
$uri = $this->communicator->getUri('invoices/invoice_get_pdf');
$uri .= "?token=$token";
if (!$applyGraphics) {
$uri .= '&gfx=0';
}
return $uri;
} | [
"public",
"function",
"getInvoicePdfUri",
"(",
"$",
"token",
",",
"$",
"applyGraphics",
"=",
"true",
")",
"{",
"$",
"uri",
"=",
"$",
"this",
"->",
"communicator",
"->",
"getUri",
"(",
"'invoices/invoice_get_pdf'",
")",
";",
"$",
"uri",
".=",
"\"?token=$token... | Returns the uri to download the invoice PDF.
@param string $token
The token for the invoice.
@param bool $applyGraphics
False to prevent any embedded graphics from being applied to the
document, true otherwise.
@return string
The uri to download the invoice PDF.
Possible errors (in download, not in return value):
- "PDFATNF04: Requested invoice for $token not found": $token does not
exist.
@see https://siel.nl/acumulus/API/Invoicing/Get_PDF_Invoice/ | [
"Returns",
"the",
"uri",
"to",
"download",
"the",
"invoice",
"PDF",
"."
] | 82f8d6c9c4929c41948c97d6cfdfac3f27c37255 | https://github.com/SIELOnline/libAcumulus/blob/82f8d6c9c4929c41948c97d6cfdfac3f27c37255/src/Web/Service.php#L494-L502 | train |
SIELOnline/libAcumulus | src/OpenCart/Invoice/Creator.php | Creator.getItemLine | protected function getItemLine(array $item)
{
$result = array();
// $product can be empty if the product has been deleted.
$product = $this->getRegistry()->model_catalog_product->getProduct($item['product_id']);
if (!empty($product)) {
$this->addPropertySource('product', $product);
}
$this->addPropertySource('item', $item);
$this->addProductInfo($result);
// Get vat range info from item line.
$productPriceEx = $item['price'];
$productVat = $item['tax'];
$vatInfo = $this->getVatRangeTags($productVat, $productPriceEx, $this->precision, $this->precision);
// Try to look up the vat rate via product.
$vatInfo += $this->getVatRateLookupMetadata($product['tax_class_id']);
// Check for cost price and margin scheme.
if (!empty($line['costPrice']) && $this->allowMarginScheme()) {
// Margin scheme:
// - Do not put VAT on invoice: send price incl VAT as unitprice.
// - But still send the VAT rate to Acumulus.
$result[Tag::UnitPrice] = $productPriceEx + $productVat;
} else {
$result[Tag::UnitPrice] = $productPriceEx;
$result[Meta::VatAmount] = $productVat;
}
$result[Tag::Quantity] = $item['quantity'];
$result += $vatInfo;
// Options (variants).
$options = $this->getOrderModel()->getOrderOptions($item['order_id'], $item['order_product_id']);
if (!empty($options)) {
// Add options as children.
$result[Meta::ChildrenLines] = array();
$optionsVatInfo = $vatInfo;
$optionsVatInfo[Meta::VatAmount] = 0;
foreach ($options as $option) {
$result[Meta::ChildrenLines][] = array(
Tag::Product => "{$option['name']}: {$option['value']}",
Tag::UnitPrice => 0,
// Table order_option does not have a quantity field, so
// composite products with multiple same sub product
// are apparently not covered. Take quantity from parent.
Tag::Quantity => $item['quantity'],
) + $optionsVatInfo;
}
}
$this->removePropertySource('product');
$this->removePropertySource('item');
return $result;
} | php | protected function getItemLine(array $item)
{
$result = array();
// $product can be empty if the product has been deleted.
$product = $this->getRegistry()->model_catalog_product->getProduct($item['product_id']);
if (!empty($product)) {
$this->addPropertySource('product', $product);
}
$this->addPropertySource('item', $item);
$this->addProductInfo($result);
// Get vat range info from item line.
$productPriceEx = $item['price'];
$productVat = $item['tax'];
$vatInfo = $this->getVatRangeTags($productVat, $productPriceEx, $this->precision, $this->precision);
// Try to look up the vat rate via product.
$vatInfo += $this->getVatRateLookupMetadata($product['tax_class_id']);
// Check for cost price and margin scheme.
if (!empty($line['costPrice']) && $this->allowMarginScheme()) {
// Margin scheme:
// - Do not put VAT on invoice: send price incl VAT as unitprice.
// - But still send the VAT rate to Acumulus.
$result[Tag::UnitPrice] = $productPriceEx + $productVat;
} else {
$result[Tag::UnitPrice] = $productPriceEx;
$result[Meta::VatAmount] = $productVat;
}
$result[Tag::Quantity] = $item['quantity'];
$result += $vatInfo;
// Options (variants).
$options = $this->getOrderModel()->getOrderOptions($item['order_id'], $item['order_product_id']);
if (!empty($options)) {
// Add options as children.
$result[Meta::ChildrenLines] = array();
$optionsVatInfo = $vatInfo;
$optionsVatInfo[Meta::VatAmount] = 0;
foreach ($options as $option) {
$result[Meta::ChildrenLines][] = array(
Tag::Product => "{$option['name']}: {$option['value']}",
Tag::UnitPrice => 0,
// Table order_option does not have a quantity field, so
// composite products with multiple same sub product
// are apparently not covered. Take quantity from parent.
Tag::Quantity => $item['quantity'],
) + $optionsVatInfo;
}
}
$this->removePropertySource('product');
$this->removePropertySource('item');
return $result;
} | [
"protected",
"function",
"getItemLine",
"(",
"array",
"$",
"item",
")",
"{",
"$",
"result",
"=",
"array",
"(",
")",
";",
"// $product can be empty if the product has been deleted.",
"$",
"product",
"=",
"$",
"this",
"->",
"getRegistry",
"(",
")",
"->",
"model_ca... | Returns the item line for 1 product line.
This method may return child lines if there are options/variants.
These lines will be informative, their price will be 0.
@param array $item
@return array
@throws \Exception | [
"Returns",
"the",
"item",
"line",
"for",
"1",
"product",
"line",
"."
] | 82f8d6c9c4929c41948c97d6cfdfac3f27c37255 | https://github.com/SIELOnline/libAcumulus/blob/82f8d6c9c4929c41948c97d6cfdfac3f27c37255/src/OpenCart/Invoice/Creator.php#L101-L157 | train |
SIELOnline/libAcumulus | src/OpenCart/Invoice/Creator.php | Creator.getVatRateLookupMetadata | protected function getVatRateLookupMetadata($taxClassId)
{
$result = array();
$taxClass = $this->getTaxClass($taxClassId);
if ($taxClass) {
$result += array(
Meta::VatClassId => $taxClass['tax_class_id'],
Meta::VatClassName => $taxClass['title'],
Meta::VatRateLookup => array(),
Meta::VatRateLookupLabel => array(),
);
$taxRules = $this->getTaxRules($taxClassId);
foreach ($taxRules as $taxRule) {
$taxRate = $this->getTaxRate($taxRule['tax_rate_id']);
if (!empty($taxRate)) {
if ($this->isAddressInGeoZone($this->order, $taxRule['based'], $taxRate['geo_zone_id'])) {
$result[Meta::VatRateLookup][] = $taxRate['rate'];
$result[Meta::VatRateLookupLabel][] = $taxRate['name'];
}
}
}
}
return $result;
} | php | protected function getVatRateLookupMetadata($taxClassId)
{
$result = array();
$taxClass = $this->getTaxClass($taxClassId);
if ($taxClass) {
$result += array(
Meta::VatClassId => $taxClass['tax_class_id'],
Meta::VatClassName => $taxClass['title'],
Meta::VatRateLookup => array(),
Meta::VatRateLookupLabel => array(),
);
$taxRules = $this->getTaxRules($taxClassId);
foreach ($taxRules as $taxRule) {
$taxRate = $this->getTaxRate($taxRule['tax_rate_id']);
if (!empty($taxRate)) {
if ($this->isAddressInGeoZone($this->order, $taxRule['based'], $taxRate['geo_zone_id'])) {
$result[Meta::VatRateLookup][] = $taxRate['rate'];
$result[Meta::VatRateLookupLabel][] = $taxRate['name'];
}
}
}
}
return $result;
} | [
"protected",
"function",
"getVatRateLookupMetadata",
"(",
"$",
"taxClassId",
")",
"{",
"$",
"result",
"=",
"array",
"(",
")",
";",
"$",
"taxClass",
"=",
"$",
"this",
"->",
"getTaxClass",
"(",
"$",
"taxClassId",
")",
";",
"if",
"(",
"$",
"taxClass",
")",
... | Looks up and returns vat class and vat rate metadata.
@param int $taxClassId
The tax class to look up.
@return array
An empty array or an array with keys:
- Meta::VatClassId: int
- Meta::VatClassName: string
- Meta::VatRateLookup: float[]
- Meta::VatRateLookupLabel: string[]
@throws \Exception | [
"Looks",
"up",
"and",
"returns",
"vat",
"class",
"and",
"vat",
"rate",
"metadata",
"."
] | 82f8d6c9c4929c41948c97d6cfdfac3f27c37255 | https://github.com/SIELOnline/libAcumulus/blob/82f8d6c9c4929c41948c97d6cfdfac3f27c37255/src/OpenCart/Invoice/Creator.php#L174-L199 | train |
SIELOnline/libAcumulus | src/OpenCart/Invoice/Creator.php | Creator.getTotalLine | protected function getTotalLine(array $line, $exVat)
{
$result = array(
Tag::Product => $line['title'],
Tag::Quantity => 1,
);
if ($exVat) {
$result[Tag::UnitPrice] = $line['value'];
} else {
$result[Meta::UnitPriceInc] = $line['value'];
}
if ($line['code'] === 'voucher') {
// A voucher is to be seen as a partial payment, thus no tax.
$result += array(
Tag::VatRate => -1,
Meta::VatRateSource => Creator::VatRateSource_Exact0,
);
} elseif ($line['code'] === 'coupon') {
// Coupons may have to be split over various taxes.
$result += array(
Tag::VatRate => null,
Meta::VatRateSource => Creator::VatRateSource_Strategy,
Meta::StrategySplit => $line['code'] === 'coupon',
);
} else {
// Try to get a vat rate.
$vatRateLookupMetaData = $this->getVatRateLookupByTotalLineType($line['code']);
// The completor will add the looked up vat rate based on looked up
// or just the highest appearing vat rate, or wil pass it to the
// strategy phase.
$result += array(
Tag::VatRate => null,
Meta::VatRateSource => Creator::VatRateSource_Completor,
Meta::StrategySplit => false,
) + $vatRateLookupMetaData;
}
return $result;
} | php | protected function getTotalLine(array $line, $exVat)
{
$result = array(
Tag::Product => $line['title'],
Tag::Quantity => 1,
);
if ($exVat) {
$result[Tag::UnitPrice] = $line['value'];
} else {
$result[Meta::UnitPriceInc] = $line['value'];
}
if ($line['code'] === 'voucher') {
// A voucher is to be seen as a partial payment, thus no tax.
$result += array(
Tag::VatRate => -1,
Meta::VatRateSource => Creator::VatRateSource_Exact0,
);
} elseif ($line['code'] === 'coupon') {
// Coupons may have to be split over various taxes.
$result += array(
Tag::VatRate => null,
Meta::VatRateSource => Creator::VatRateSource_Strategy,
Meta::StrategySplit => $line['code'] === 'coupon',
);
} else {
// Try to get a vat rate.
$vatRateLookupMetaData = $this->getVatRateLookupByTotalLineType($line['code']);
// The completor will add the looked up vat rate based on looked up
// or just the highest appearing vat rate, or wil pass it to the
// strategy phase.
$result += array(
Tag::VatRate => null,
Meta::VatRateSource => Creator::VatRateSource_Completor,
Meta::StrategySplit => false,
) + $vatRateLookupMetaData;
}
return $result;
} | [
"protected",
"function",
"getTotalLine",
"(",
"array",
"$",
"line",
",",
"$",
"exVat",
")",
"{",
"$",
"result",
"=",
"array",
"(",
"Tag",
"::",
"Product",
"=>",
"$",
"line",
"[",
"'title'",
"]",
",",
"Tag",
"::",
"Quantity",
"=>",
"1",
",",
")",
";... | Returns a line based on a "order total line".
@param array $line
The total line.
@param bool $exVat
Whether the value in this line is ex (true) or inc (false) vat.
@return array
An Acumulus invoice line.
@throws \Exception | [
"Returns",
"a",
"line",
"based",
"on",
"a",
"order",
"total",
"line",
"."
] | 82f8d6c9c4929c41948c97d6cfdfac3f27c37255 | https://github.com/SIELOnline/libAcumulus/blob/82f8d6c9c4929c41948c97d6cfdfac3f27c37255/src/OpenCart/Invoice/Creator.php#L276-L315 | train |
SIELOnline/libAcumulus | src/OpenCart/Invoice/Creator.php | Creator.getVatRateLookupByTotalLineType | protected function getVatRateLookupByTotalLineType($code)
{
$result = array();
$query = $this->getTotalLineTaxClassLookupQuery($code);
$queryResult = $this->getRegistry()->db->query($query);
if (!empty($queryResult->row)) {
$taxClassId = reset($queryResult->row);
$result = $this->getVatRateLookupMetadata($taxClassId);
}
return $result;
} | php | protected function getVatRateLookupByTotalLineType($code)
{
$result = array();
$query = $this->getTotalLineTaxClassLookupQuery($code);
$queryResult = $this->getRegistry()->db->query($query);
if (!empty($queryResult->row)) {
$taxClassId = reset($queryResult->row);
$result = $this->getVatRateLookupMetadata($taxClassId);
}
return $result;
} | [
"protected",
"function",
"getVatRateLookupByTotalLineType",
"(",
"$",
"code",
")",
"{",
"$",
"result",
"=",
"array",
"(",
")",
";",
"$",
"query",
"=",
"$",
"this",
"->",
"getTotalLineTaxClassLookupQuery",
"(",
"$",
"code",
")",
";",
"$",
"queryResult",
"=",
... | Tries to lookup and return vat rate meta data for the given line type.
This is quite hard. The total line (table order_total) contains a code
(= line type) and title field, the latter being a translated and possibly
formatted descriptive string of the shipping or handling method applied,
e.g. Europa (Weight: 3.00kg). It is (almost) impossible to trace this
back to a shipping or handling method. So instead we retrieve all tax
class ids for the given type, collect all tax rates for those, and hope
that this results in only 1 tax rate.
@param string $code
The total line type: shipping, handling, low_order_fee, ... (no other
known types).
@return array
A, possibly empty, array with vat rate lookup meta data. Empty if no or
multiple tax rates were found.
@throws \Exception | [
"Tries",
"to",
"lookup",
"and",
"return",
"vat",
"rate",
"meta",
"data",
"for",
"the",
"given",
"line",
"type",
"."
] | 82f8d6c9c4929c41948c97d6cfdfac3f27c37255 | https://github.com/SIELOnline/libAcumulus/blob/82f8d6c9c4929c41948c97d6cfdfac3f27c37255/src/OpenCart/Invoice/Creator.php#L338-L348 | train |
SIELOnline/libAcumulus | src/OpenCart/Invoice/Creator.php | Creator.isAddressInGeoZone | protected function isAddressInGeoZone(array $order, $addressType, $geoZoneId)
{
$fallbackAddressType = $addressType === 'payment' ? 'shipping' : 'payment';
if (!empty($order["{$addressType}_country_id"])) {
$countryId = $order["{$addressType}_country_id"];
$zoneId = !empty($order["{$addressType}_zone_id"]) ? $order["{$addressType}_zone_id"] : 0;
} elseif (!empty($order["{$fallbackAddressType}_country_id"])) {
$countryId = $order["{$fallbackAddressType}_country_id"];
$zoneId = !empty($order["{$fallbackAddressType}_zone_id"]) ? $order["{$fallbackAddressType}_zone_id"] : 0;
} else {
$countryId = 0;
$zoneId = 0;
}
$zones = $this->getZoneToGeoZones($geoZoneId);
foreach ($zones as $zone) {
// Check if this zone definition covers the same country.
if ($zone['country_id'] == $countryId) {
// Check if the zone definition covers the whole country or if
// they are equal.
if ($zone['zone_id'] == 0 || $zone['zone_id'] == $zoneId) {
return true;
}
}
}
return false;
} | php | protected function isAddressInGeoZone(array $order, $addressType, $geoZoneId)
{
$fallbackAddressType = $addressType === 'payment' ? 'shipping' : 'payment';
if (!empty($order["{$addressType}_country_id"])) {
$countryId = $order["{$addressType}_country_id"];
$zoneId = !empty($order["{$addressType}_zone_id"]) ? $order["{$addressType}_zone_id"] : 0;
} elseif (!empty($order["{$fallbackAddressType}_country_id"])) {
$countryId = $order["{$fallbackAddressType}_country_id"];
$zoneId = !empty($order["{$fallbackAddressType}_zone_id"]) ? $order["{$fallbackAddressType}_zone_id"] : 0;
} else {
$countryId = 0;
$zoneId = 0;
}
$zones = $this->getZoneToGeoZones($geoZoneId);
foreach ($zones as $zone) {
// Check if this zone definition covers the same country.
if ($zone['country_id'] == $countryId) {
// Check if the zone definition covers the whole country or if
// they are equal.
if ($zone['zone_id'] == 0 || $zone['zone_id'] == $zoneId) {
return true;
}
}
}
return false;
} | [
"protected",
"function",
"isAddressInGeoZone",
"(",
"array",
"$",
"order",
",",
"$",
"addressType",
",",
"$",
"geoZoneId",
")",
"{",
"$",
"fallbackAddressType",
"=",
"$",
"addressType",
"===",
"'payment'",
"?",
"'shipping'",
":",
"'payment'",
";",
"if",
"(",
... | Returns whether the address of the order lies within the geo zone.
@param array $order
The order.
@param string $addressType
'payment' or 'shipping'.
@param int $geoZoneId
The id of the geo zone.
@return bool
True if the address of the order lies within the geo zone, false
otherwise.
@throws \Exception | [
"Returns",
"whether",
"the",
"address",
"of",
"the",
"order",
"lies",
"within",
"the",
"geo",
"zone",
"."
] | 82f8d6c9c4929c41948c97d6cfdfac3f27c37255 | https://github.com/SIELOnline/libAcumulus/blob/82f8d6c9c4929c41948c97d6cfdfac3f27c37255/src/OpenCart/Invoice/Creator.php#L366-L392 | train |
SIELOnline/libAcumulus | src/MyWebShop/Helpers/Log.php | Log.getMyWebShopSeverity | protected function getMyWebShopSeverity($severity)
{
switch ($severity) {
case Log::Error:
return AbstractLogger::ERROR;
case Log::Warning:
return AbstractLogger::WARNING;
case Log::Notice:
case Log::Info:
return AbstractLogger::INFO;
case Log::Debug:
default:
return AbstractLogger::DEBUG;
}
} | php | protected function getMyWebShopSeverity($severity)
{
switch ($severity) {
case Log::Error:
return AbstractLogger::ERROR;
case Log::Warning:
return AbstractLogger::WARNING;
case Log::Notice:
case Log::Info:
return AbstractLogger::INFO;
case Log::Debug:
default:
return AbstractLogger::DEBUG;
}
} | [
"protected",
"function",
"getMyWebShopSeverity",
"(",
"$",
"severity",
")",
"{",
"switch",
"(",
"$",
"severity",
")",
"{",
"case",
"Log",
"::",
"Error",
":",
"return",
"AbstractLogger",
"::",
"ERROR",
";",
"case",
"Log",
"::",
"Warning",
":",
"return",
"Ab... | Returns the MyWebShop equivalent of the severity.
@param int $severity
One of the constants of the base Log class.
@return int
The MyWebShop equivalent of the severity. | [
"Returns",
"the",
"MyWebShop",
"equivalent",
"of",
"the",
"severity",
"."
] | 82f8d6c9c4929c41948c97d6cfdfac3f27c37255 | https://github.com/SIELOnline/libAcumulus/blob/82f8d6c9c4929c41948c97d6cfdfac3f27c37255/src/MyWebShop/Helpers/Log.php#L38-L52 | train |
SIELOnline/libAcumulus | src/MyWebShop/Helpers/Log.php | Log.getLogger | protected function getLogger()
{
if ($this->logger === null) {
// @todo: Instantiate a webshop specific log object that logs to a separate Acumulus log file.
$this->logger = new FileLogger(AbstractLogger::DEBUG);
$this->logger->setFilename(_ROOT_DIR_ . '/'. $logDirectory . '/acumulus.log');
}
return $this->logger;
} | php | protected function getLogger()
{
if ($this->logger === null) {
// @todo: Instantiate a webshop specific log object that logs to a separate Acumulus log file.
$this->logger = new FileLogger(AbstractLogger::DEBUG);
$this->logger->setFilename(_ROOT_DIR_ . '/'. $logDirectory . '/acumulus.log');
}
return $this->logger;
} | [
"protected",
"function",
"getLogger",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"logger",
"===",
"null",
")",
"{",
"// @todo: Instantiate a webshop specific log object that logs to a separate Acumulus log file.",
"$",
"this",
"->",
"logger",
"=",
"new",
"FileLogger",... | Returns the MyWebShop specific logger.
@return \AbstractLogger | [
"Returns",
"the",
"MyWebShop",
"specific",
"logger",
"."
] | 82f8d6c9c4929c41948c97d6cfdfac3f27c37255 | https://github.com/SIELOnline/libAcumulus/blob/82f8d6c9c4929c41948c97d6cfdfac3f27c37255/src/MyWebShop/Helpers/Log.php#L60-L68 | train |
SIELOnline/libAcumulus | src/Joomla/Shop/InvoiceManager.php | InvoiceManager.toSql | protected function toSql($date)
{
$tz = new DateTimeZone(JFactory::getApplication()->get('offset'));
$date = new JDate($date);
$date->setTimezone($tz);
return $date->toSql(true);
} | php | protected function toSql($date)
{
$tz = new DateTimeZone(JFactory::getApplication()->get('offset'));
$date = new JDate($date);
$date->setTimezone($tz);
return $date->toSql(true);
} | [
"protected",
"function",
"toSql",
"(",
"$",
"date",
")",
"{",
"$",
"tz",
"=",
"new",
"DateTimeZone",
"(",
"JFactory",
"::",
"getApplication",
"(",
")",
"->",
"get",
"(",
"'offset'",
")",
")",
";",
"$",
"date",
"=",
"new",
"JDate",
"(",
"$",
"date",
... | Helper method that returns a date in the correct and escaped sql format.
@param string $date
Date in yyyy-mm-dd format.
@return string
@throws \Exception | [
"Helper",
"method",
"that",
"returns",
"a",
"date",
"in",
"the",
"correct",
"and",
"escaped",
"sql",
"format",
"."
] | 82f8d6c9c4929c41948c97d6cfdfac3f27c37255 | https://github.com/SIELOnline/libAcumulus/blob/82f8d6c9c4929c41948c97d6cfdfac3f27c37255/src/Joomla/Shop/InvoiceManager.php#L71-L77 | train |
SIELOnline/libAcumulus | src/Invoice/Creator.php | Creator.setInvoiceSource | protected function setInvoiceSource($invoiceSource)
{
$this->invoiceSource = $invoiceSource;
if (!in_array($invoiceSource->getType(), array(Source::Order, Source::CreditNote))) {
$this->log->error('Creator::setSource(): unknown source type %s', $this->invoiceSource->getType());
};
} | php | protected function setInvoiceSource($invoiceSource)
{
$this->invoiceSource = $invoiceSource;
if (!in_array($invoiceSource->getType(), array(Source::Order, Source::CreditNote))) {
$this->log->error('Creator::setSource(): unknown source type %s', $this->invoiceSource->getType());
};
} | [
"protected",
"function",
"setInvoiceSource",
"(",
"$",
"invoiceSource",
")",
"{",
"$",
"this",
"->",
"invoiceSource",
"=",
"$",
"invoiceSource",
";",
"if",
"(",
"!",
"in_array",
"(",
"$",
"invoiceSource",
"->",
"getType",
"(",
")",
",",
"array",
"(",
"Sour... | Sets the source to create the invoice for.
@param Source $invoiceSource | [
"Sets",
"the",
"source",
"to",
"create",
"the",
"invoice",
"for",
"."
] | 82f8d6c9c4929c41948c97d6cfdfac3f27c37255 | https://github.com/SIELOnline/libAcumulus/blob/82f8d6c9c4929c41948c97d6cfdfac3f27c37255/src/Invoice/Creator.php#L179-L185 | train |
SIELOnline/libAcumulus | src/Invoice/Creator.php | Creator.setPropertySources | protected function setPropertySources()
{
$this->propertySources = array();
$this->propertySources['invoiceSource'] = $this->invoiceSource;
if (array_key_exists(Source::CreditNote, $this->shopCapabilities->getSupportedInvoiceSourceTypes())) {
$this->propertySources['originalInvoiceSource'] = $this->invoiceSource->getOrder();
}
$this->propertySources['source'] = $this->invoiceSource->getSource();
if (array_key_exists(Source::CreditNote, $this->shopCapabilities->getSupportedInvoiceSourceTypes())) {
if ($this->invoiceSource->getType() === Source::CreditNote) {
$this->propertySources['refund'] = $this->invoiceSource->getSource();
}
$this->propertySources['order'] = $this->invoiceSource->getOrder()->getSource();
if ($this->invoiceSource->getType() === Source::CreditNote) {
$this->propertySources['refundedInvoiceSource'] = $this->invoiceSource->getOrder();
$this->propertySources['refundedOrder'] = $this->invoiceSource->getOrder()->getSource();
}
}
} | php | protected function setPropertySources()
{
$this->propertySources = array();
$this->propertySources['invoiceSource'] = $this->invoiceSource;
if (array_key_exists(Source::CreditNote, $this->shopCapabilities->getSupportedInvoiceSourceTypes())) {
$this->propertySources['originalInvoiceSource'] = $this->invoiceSource->getOrder();
}
$this->propertySources['source'] = $this->invoiceSource->getSource();
if (array_key_exists(Source::CreditNote, $this->shopCapabilities->getSupportedInvoiceSourceTypes())) {
if ($this->invoiceSource->getType() === Source::CreditNote) {
$this->propertySources['refund'] = $this->invoiceSource->getSource();
}
$this->propertySources['order'] = $this->invoiceSource->getOrder()->getSource();
if ($this->invoiceSource->getType() === Source::CreditNote) {
$this->propertySources['refundedInvoiceSource'] = $this->invoiceSource->getOrder();
$this->propertySources['refundedOrder'] = $this->invoiceSource->getOrder()->getSource();
}
}
} | [
"protected",
"function",
"setPropertySources",
"(",
")",
"{",
"$",
"this",
"->",
"propertySources",
"=",
"array",
"(",
")",
";",
"$",
"this",
"->",
"propertySources",
"[",
"'invoiceSource'",
"]",
"=",
"$",
"this",
"->",
"invoiceSource",
";",
"if",
"(",
"ar... | Sets the list of sources to search for a property when expanding tokens. | [
"Sets",
"the",
"list",
"of",
"sources",
"to",
"search",
"for",
"a",
"property",
"when",
"expanding",
"tokens",
"."
] | 82f8d6c9c4929c41948c97d6cfdfac3f27c37255 | https://github.com/SIELOnline/libAcumulus/blob/82f8d6c9c4929c41948c97d6cfdfac3f27c37255/src/Invoice/Creator.php#L190-L208 | train |
SIELOnline/libAcumulus | src/Invoice/Creator.php | Creator.create | public function create($source)
{
$this->setInvoiceSource($source);
$this->setPropertySources();
$this->invoice = array();
$this->invoice[Tag::Customer] = $this->getCustomer();
$this->invoice[Tag::Customer][Tag::Invoice] = $this->getInvoice();
$this->invoice[Tag::Customer][Tag::Invoice][Tag::Line] = $this->getInvoiceLines();
$emailAsPdf = $this->getEmailAsPdf(!empty($this->invoice[Tag::Customer][Tag::Email]) ? $this->invoice[Tag::Customer][Tag::Email] : '');
if (!empty($emailAsPdf)) {
$this->invoice[Tag::Customer][Tag::Invoice][Tag::EmailAsPdf] = $emailAsPdf;
}
return $this->invoice;
} | php | public function create($source)
{
$this->setInvoiceSource($source);
$this->setPropertySources();
$this->invoice = array();
$this->invoice[Tag::Customer] = $this->getCustomer();
$this->invoice[Tag::Customer][Tag::Invoice] = $this->getInvoice();
$this->invoice[Tag::Customer][Tag::Invoice][Tag::Line] = $this->getInvoiceLines();
$emailAsPdf = $this->getEmailAsPdf(!empty($this->invoice[Tag::Customer][Tag::Email]) ? $this->invoice[Tag::Customer][Tag::Email] : '');
if (!empty($emailAsPdf)) {
$this->invoice[Tag::Customer][Tag::Invoice][Tag::EmailAsPdf] = $emailAsPdf;
}
return $this->invoice;
} | [
"public",
"function",
"create",
"(",
"$",
"source",
")",
"{",
"$",
"this",
"->",
"setInvoiceSource",
"(",
"$",
"source",
")",
";",
"$",
"this",
"->",
"setPropertySources",
"(",
")",
";",
"$",
"this",
"->",
"invoice",
"=",
"array",
"(",
")",
";",
"$",... | Creates an Acumulus invoice from an order or credit note.
@param Source $source
The web shop order.
@return array
The acumulus invoice for this order. | [
"Creates",
"an",
"Acumulus",
"invoice",
"from",
"an",
"order",
"or",
"credit",
"note",
"."
] | 82f8d6c9c4929c41948c97d6cfdfac3f27c37255 | https://github.com/SIELOnline/libAcumulus/blob/82f8d6c9c4929c41948c97d6cfdfac3f27c37255/src/Invoice/Creator.php#L246-L259 | train |
SIELOnline/libAcumulus | src/Invoice/Creator.php | Creator.getCustomer | protected function getCustomer()
{
$customer = array();
$customerSettings = $this->config->getCustomerSettings();
$this->addDefault($customer, Tag::Type, $customerSettings['defaultCustomerType']);
$this->addTokenDefault($customer, Tag::ContactYourId, $customerSettings['contactYourId']);
$this->addDefaultEmpty($customer, Tag::ContactStatus, $customerSettings['contactStatus']);
$this->addTokenDefault($customer, Tag::CompanyName1, $customerSettings['companyName1']);
$this->addTokenDefault($customer, Tag::CompanyName2, $customerSettings['companyName2']);
$this->addTokenDefault($customer, Tag::VatNumber, $customerSettings['vatNumber']);
$this->addTokenDefault($customer, Tag::FullName, $customerSettings['fullName']);
$this->addTokenDefault($customer, Tag::Salutation, $customerSettings['salutation']);
$this->addTokenDefault($customer, Tag::Address1, $customerSettings['address1']);
$this->addTokenDefault($customer, Tag::Address2, $customerSettings['address2']);
$this->addTokenDefault($customer, Tag::PostalCode, $customerSettings['postalCode']);
$this->addTokenDefault($customer, Tag::City, $customerSettings['city']);
$customer[Tag::CountryCode] = $this->countries->convertEuCountryCode($this->invoiceSource->getCountryCode());
// Add 'nl' as default country code. As other methods in the creator may
// depend on this value being filled, e.g. looking up product vat rates,
// we cannot wait until the completion phase, so we add it here.
$this->addDefault($customer, Tag::CountryCode, 'nl');
$this->addDefault($customer, Tag::Country, $this->countries->getCountryName($customer[Tag::CountryCode]));
$this->addTokenDefault($customer, Tag::Telephone, $customerSettings['telephone']);
$this->addTokenDefault($customer, Tag::Fax, $customerSettings['fax']);
$this->addTokenDefault($customer, Tag::Email, $customerSettings['email']);
$this->addDefaultEmpty($customer, Tag::OverwriteIfExists, $customerSettings['overwriteIfExists'] ? Api::OverwriteIfExists_Yes : Api::OverwriteIfExists_No);
$this->addTokenDefault($customer, Tag::Mark, $customerSettings['mark']);
return $customer;
} | php | protected function getCustomer()
{
$customer = array();
$customerSettings = $this->config->getCustomerSettings();
$this->addDefault($customer, Tag::Type, $customerSettings['defaultCustomerType']);
$this->addTokenDefault($customer, Tag::ContactYourId, $customerSettings['contactYourId']);
$this->addDefaultEmpty($customer, Tag::ContactStatus, $customerSettings['contactStatus']);
$this->addTokenDefault($customer, Tag::CompanyName1, $customerSettings['companyName1']);
$this->addTokenDefault($customer, Tag::CompanyName2, $customerSettings['companyName2']);
$this->addTokenDefault($customer, Tag::VatNumber, $customerSettings['vatNumber']);
$this->addTokenDefault($customer, Tag::FullName, $customerSettings['fullName']);
$this->addTokenDefault($customer, Tag::Salutation, $customerSettings['salutation']);
$this->addTokenDefault($customer, Tag::Address1, $customerSettings['address1']);
$this->addTokenDefault($customer, Tag::Address2, $customerSettings['address2']);
$this->addTokenDefault($customer, Tag::PostalCode, $customerSettings['postalCode']);
$this->addTokenDefault($customer, Tag::City, $customerSettings['city']);
$customer[Tag::CountryCode] = $this->countries->convertEuCountryCode($this->invoiceSource->getCountryCode());
// Add 'nl' as default country code. As other methods in the creator may
// depend on this value being filled, e.g. looking up product vat rates,
// we cannot wait until the completion phase, so we add it here.
$this->addDefault($customer, Tag::CountryCode, 'nl');
$this->addDefault($customer, Tag::Country, $this->countries->getCountryName($customer[Tag::CountryCode]));
$this->addTokenDefault($customer, Tag::Telephone, $customerSettings['telephone']);
$this->addTokenDefault($customer, Tag::Fax, $customerSettings['fax']);
$this->addTokenDefault($customer, Tag::Email, $customerSettings['email']);
$this->addDefaultEmpty($customer, Tag::OverwriteIfExists, $customerSettings['overwriteIfExists'] ? Api::OverwriteIfExists_Yes : Api::OverwriteIfExists_No);
$this->addTokenDefault($customer, Tag::Mark, $customerSettings['mark']);
return $customer;
} | [
"protected",
"function",
"getCustomer",
"(",
")",
"{",
"$",
"customer",
"=",
"array",
"(",
")",
";",
"$",
"customerSettings",
"=",
"$",
"this",
"->",
"config",
"->",
"getCustomerSettings",
"(",
")",
";",
"$",
"this",
"->",
"addDefault",
"(",
"$",
"custom... | Returns the 'customer' part of the invoice add structure.
The following keys are allowed/expected by the API:
- type
- contactid: will not be set. Acumulus id for this customer, in the
absence of this value, the API uses the email address as identifying
value.
- contactyourid: webshop customer id.
- contactstatus
- companyname1
- companyname2
- vatnumber
- fullname
- salutation
- address1
- address2
- postalcode
- city
- countrycode
- country
- telephone
- fax
- email: used to identify clients.
- overwriteifexists
- bankaccountnumber: will not be set: no webshop software provides this.
- mark
- disableduplicates: not (yet) supported.
At the customer level no meta tags are defined.
Extending classes should normally not have to override this method as all
values are fetched via configurable settings that may contain tokens
(veldverwijzingen (Dutch)) that refer to properties of objects in the
webshop (property sources). The exception is the (ISO) country code which
may not be easy to fetch via a property source as this might include a
database lookup to a "Countries" table. This is fetched via
Source::getCountryCode().
@return array
A keyed array with the customer data. | [
"Returns",
"the",
"customer",
"part",
"of",
"the",
"invoice",
"add",
"structure",
"."
] | 82f8d6c9c4929c41948c97d6cfdfac3f27c37255 | https://github.com/SIELOnline/libAcumulus/blob/82f8d6c9c4929c41948c97d6cfdfac3f27c37255/src/Invoice/Creator.php#L303-L331 | train |
SIELOnline/libAcumulus | src/Invoice/Creator.php | Creator.getInvoiceNumber | protected function getInvoiceNumber($invoiceNumberSource)
{
$result = $invoiceNumberSource === PluginConfig::InvoiceNrSource_ShopInvoice ? $this->invoiceSource->getInvoiceReference() : null;
if (empty($result)) {
$result = $this->invoiceSource->getReference();
}
return $result;
} | php | protected function getInvoiceNumber($invoiceNumberSource)
{
$result = $invoiceNumberSource === PluginConfig::InvoiceNrSource_ShopInvoice ? $this->invoiceSource->getInvoiceReference() : null;
if (empty($result)) {
$result = $this->invoiceSource->getReference();
}
return $result;
} | [
"protected",
"function",
"getInvoiceNumber",
"(",
"$",
"invoiceNumberSource",
")",
"{",
"$",
"result",
"=",
"$",
"invoiceNumberSource",
"===",
"PluginConfig",
"::",
"InvoiceNrSource_ShopInvoice",
"?",
"$",
"this",
"->",
"invoiceSource",
"->",
"getInvoiceReference",
"(... | Returns the number to use as invoice number.
@param int $invoiceNumberSource
\Siel\Acumulus\PluginConfig::InvoiceNrSource_ShopInvoice or
\Siel\Acumulus\PluginConfig::InvoiceNrSource_ShopOrder.
@return int
The number to use as invoice "number" on the Acumulus invoice. Note
that Acumulus expects a number and does not accept string prefixes or
such. | [
"Returns",
"the",
"number",
"to",
"use",
"as",
"invoice",
"number",
"."
] | 82f8d6c9c4929c41948c97d6cfdfac3f27c37255 | https://github.com/SIELOnline/libAcumulus/blob/82f8d6c9c4929c41948c97d6cfdfac3f27c37255/src/Invoice/Creator.php#L462-L469 | train |
SIELOnline/libAcumulus | src/Invoice/Creator.php | Creator.getInvoiceDate | protected function getInvoiceDate($dateToUse)
{
$result = $this->invoiceSource->getInvoiceDate();
if ($dateToUse != PluginConfig::InvoiceDate_OrderCreate || empty($result)) {
$result = $this->invoiceSource->getDate();
}
return $result;
} | php | protected function getInvoiceDate($dateToUse)
{
$result = $this->invoiceSource->getInvoiceDate();
if ($dateToUse != PluginConfig::InvoiceDate_OrderCreate || empty($result)) {
$result = $this->invoiceSource->getDate();
}
return $result;
} | [
"protected",
"function",
"getInvoiceDate",
"(",
"$",
"dateToUse",
")",
"{",
"$",
"result",
"=",
"$",
"this",
"->",
"invoiceSource",
"->",
"getInvoiceDate",
"(",
")",
";",
"if",
"(",
"$",
"dateToUse",
"!=",
"PluginConfig",
"::",
"InvoiceDate_OrderCreate",
"||",... | Returns the date to use as invoice date.
@param int $dateToUse
\Siel\Acumulus\PluginConfig::InvoiceDate_InvoiceCreate or
\Siel\Acumulus\PluginConfig::InvoiceDate_OrderCreate
@return string
Date to use as invoice date on the Acumulus invoice: yyyy-mm-dd. | [
"Returns",
"the",
"date",
"to",
"use",
"as",
"invoice",
"date",
"."
] | 82f8d6c9c4929c41948c97d6cfdfac3f27c37255 | https://github.com/SIELOnline/libAcumulus/blob/82f8d6c9c4929c41948c97d6cfdfac3f27c37255/src/Invoice/Creator.php#L481-L488 | train |
SIELOnline/libAcumulus | src/Invoice/Creator.php | Creator.getInvoiceLines | protected function getInvoiceLines()
{
$itemLines = $this->getItemLines();
$itemLines = $this->addLineType($itemLines, static::LineType_OrderItem);
$feeLines = $this->getFeeLines();
$discountLines = $this->getDiscountLines();
$discountLines = $this->addLineType($discountLines, static::LineType_Discount);
$manualLines = $this->getManualLines();
$manualLines = $this->addLineType($manualLines, static::LineType_Manual);
$result = array_merge($itemLines, $feeLines, $discountLines, $manualLines);
return $result;
} | php | protected function getInvoiceLines()
{
$itemLines = $this->getItemLines();
$itemLines = $this->addLineType($itemLines, static::LineType_OrderItem);
$feeLines = $this->getFeeLines();
$discountLines = $this->getDiscountLines();
$discountLines = $this->addLineType($discountLines, static::LineType_Discount);
$manualLines = $this->getManualLines();
$manualLines = $this->addLineType($manualLines, static::LineType_Manual);
$result = array_merge($itemLines, $feeLines, $discountLines, $manualLines);
return $result;
} | [
"protected",
"function",
"getInvoiceLines",
"(",
")",
"{",
"$",
"itemLines",
"=",
"$",
"this",
"->",
"getItemLines",
"(",
")",
";",
"$",
"itemLines",
"=",
"$",
"this",
"->",
"addLineType",
"(",
"$",
"itemLines",
",",
"static",
"::",
"LineType_OrderItem",
"... | Returns the 'invoice''line' parts of the invoice add structure.
Each invoice line is a keyed array.
The following keys are allowed or expected (*) by the API:
- itemnumber
- product
- nature
* unitprice
* vatrate
* quantity
- costprice: optional, this triggers margin invoices.
Meta data (not recognised by the API but used later on by the Creator or
Completor, or for support and debugging purposes), see
{@see \Siel\Acumulus\Meta}:
- Complementary to amount and vatrate:
- unitpriceinc
- vatamount
* meta-line-type: type of line: 1 of the LineType_... constants.
- vat rate related:
* meta-vatrate-source, 1 of the VatRateSource_... constants:
- exact: should exactly equal an existing VAT rate.
- exact-0: should exactly equal the 0 VAT rate.
- calculated: based on dividing vatamount and unitprice which
both may have a limited precision and therefore probably will
not exactly match an existing vat rate.
- completor: to be filled in by the completor.
- strategy: to be completed in by a tax divide strategy. This may
lead to this line being split into multiple lines.
- parent: copied from the parent.
* meta-vatrate-min: required if meta-vatrate-source is calculated.
The minimum value for the vat rate, based on the precision of the
vatamount and unitprice.
* meta-vatrate-max: required if meta-vatrate-source is calculated.
The maximum value for the vat rate, based on the precision of the
vatamount and unitprice.
- meta-strategy-split: true or false (absent = false)
- Totals per line:
- meta-line-price
- meta-line-priceinc
- meta-line-vatamount
- Parent - children line meta data:
- meta-children
- meta-children-count
- meta-parent-index
- meta-children-merged
- meta-children-not-shown
- meta-parent
-
These keys can be used to complete missing values or to assist in
correcting rounding errors in the values that are present.
The base CompletorInvoiceLines expects:
- meta-vatrate-source to be filled
- If meta-vatrate-source = exact: no other keys expected
- If meta-vatrate-source = calculated: meta-vatrate-min and
meta-vatrate-max are expected to be filled. These values should come
from calling the helper method getVatRangeTags() with the values used
to calculate the vat rate and their precision.
- If meta-vatrate-source = completor: vatrate should be null and
unitprice should be 0. The completor will typically fill vatrate with
the highest or most appearing vat rate, looking at the exact and
calculated (after correcting them for rounding errors) vat rates.
- If meta-vatrate-source = strategy: vat rate should be null and either
unitprice or unitpriceinc should be filled wit a non-0 amount
(typically a negative amount as this is mostly used for spreading
discounts over tax rates). Moreover, on the invoice level
meta-invoice-amount and meta-invoice-vatamount should be filled in.
The completor will use a tax divide strategy to arrive at valid values
for the missing fields.
Extending classes should normally not have to override this method, but
should instead implement getItemLines(), getShippingLine(),
getPaymentFeeLine(), getGiftWrappingLine(), getDiscountLines(), and
getManualLines().
@return array[]
A non keyed array with all invoice lines. | [
"Returns",
"the",
"invoice",
"line",
"parts",
"of",
"the",
"invoice",
"add",
"structure",
"."
] | 82f8d6c9c4929c41948c97d6cfdfac3f27c37255 | https://github.com/SIELOnline/libAcumulus/blob/82f8d6c9c4929c41948c97d6cfdfac3f27c37255/src/Invoice/Creator.php#L570-L585 | train |
SIELOnline/libAcumulus | src/Invoice/Creator.php | Creator.addProductInfo | protected function addProductInfo(array &$line)
{
$invoiceSettings = $this->config->getInvoiceSettings();
$this->addTokenDefault($line, Tag::ItemNumber, $invoiceSettings['itemNumber']);
$this->addTokenDefault($line, Tag::Product, $invoiceSettings['productName']);
$this->addNature($line);
if (!empty($invoiceSettings['costPrice'])) {
$value = $this->getTokenizedValue($invoiceSettings['costPrice']);
if (!Number::isZero($value)) {
// If we have a cost price we add it, even if this is no margin
// invoice.
$line[Tag::CostPrice] = $value;
}
}
} | php | protected function addProductInfo(array &$line)
{
$invoiceSettings = $this->config->getInvoiceSettings();
$this->addTokenDefault($line, Tag::ItemNumber, $invoiceSettings['itemNumber']);
$this->addTokenDefault($line, Tag::Product, $invoiceSettings['productName']);
$this->addNature($line);
if (!empty($invoiceSettings['costPrice'])) {
$value = $this->getTokenizedValue($invoiceSettings['costPrice']);
if (!Number::isZero($value)) {
// If we have a cost price we add it, even if this is no margin
// invoice.
$line[Tag::CostPrice] = $value;
}
}
} | [
"protected",
"function",
"addProductInfo",
"(",
"array",
"&",
"$",
"line",
")",
"{",
"$",
"invoiceSettings",
"=",
"$",
"this",
"->",
"config",
"->",
"getInvoiceSettings",
"(",
")",
";",
"$",
"this",
"->",
"addTokenDefault",
"(",
"$",
"line",
",",
"Tag",
... | Adds the product based tags to a line.
The product based tags are:
- item number
- product name
- nature
- cost price
@param array $line | [
"Adds",
"the",
"product",
"based",
"tags",
"to",
"a",
"line",
"."
] | 82f8d6c9c4929c41948c97d6cfdfac3f27c37255 | https://github.com/SIELOnline/libAcumulus/blob/82f8d6c9c4929c41948c97d6cfdfac3f27c37255/src/Invoice/Creator.php#L612-L626 | train |
SIELOnline/libAcumulus | src/Invoice/Creator.php | Creator.addNature | protected function addNature(array &$line)
{
if (empty($line[Tag::Nature])) {
$shopSettings = $this->config->getShopSettings();
switch ($shopSettings['nature_shop']) {
case PluginConfig::Nature_Products:
$line[Tag::Nature] = Api::Nature_Product;
break;
case PluginConfig::Nature_Services:
$line[Tag::Nature] = Api::Nature_Service;
break;
default:
$invoiceSettings = $this->config->getInvoiceSettings();
$this->addTokenDefault($line, Tag::Nature, $invoiceSettings['nature']);
break;
}
}
} | php | protected function addNature(array &$line)
{
if (empty($line[Tag::Nature])) {
$shopSettings = $this->config->getShopSettings();
switch ($shopSettings['nature_shop']) {
case PluginConfig::Nature_Products:
$line[Tag::Nature] = Api::Nature_Product;
break;
case PluginConfig::Nature_Services:
$line[Tag::Nature] = Api::Nature_Service;
break;
default:
$invoiceSettings = $this->config->getInvoiceSettings();
$this->addTokenDefault($line, Tag::Nature, $invoiceSettings['nature']);
break;
}
}
} | [
"protected",
"function",
"addNature",
"(",
"array",
"&",
"$",
"line",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"line",
"[",
"Tag",
"::",
"Nature",
"]",
")",
")",
"{",
"$",
"shopSettings",
"=",
"$",
"this",
"->",
"config",
"->",
"getShopSettings",
"(",... | Adds the nature tag to the line.
The nature tag indicates the nature of the article for which the line is
being constructed. It can be Product or Service.
The nature can come from the:
- Shop settings: the nature_shop setting.
- Invoice settings: The nature field reference.
@param array $line | [
"Adds",
"the",
"nature",
"tag",
"to",
"the",
"line",
"."
] | 82f8d6c9c4929c41948c97d6cfdfac3f27c37255 | https://github.com/SIELOnline/libAcumulus/blob/82f8d6c9c4929c41948c97d6cfdfac3f27c37255/src/Invoice/Creator.php#L640-L657 | train |
SIELOnline/libAcumulus | src/Invoice/Creator.php | Creator.getFeeLines | protected function getFeeLines()
{
$result = array();
$shippingLines = $this->getShippingLines();
if ($shippingLines) {
$shippingLines = $this->addLineType($shippingLines, static::LineType_Shipping, Api::Nature_Service);
$result = array_merge($result, $shippingLines);
}
$line = $this->getPaymentFeeLine();
if ($line) {
$line = $this->addLineType($line,static::LineType_PaymentFee, Api::Nature_Service);
$result[] = $line;
}
$line = $this->getGiftWrappingLine();
if ($line) {
$line = $this->addLineType($line,static::LineType_GiftWrapping, Api::Nature_Service);
$result[] = $line;
}
return $result;
} | php | protected function getFeeLines()
{
$result = array();
$shippingLines = $this->getShippingLines();
if ($shippingLines) {
$shippingLines = $this->addLineType($shippingLines, static::LineType_Shipping, Api::Nature_Service);
$result = array_merge($result, $shippingLines);
}
$line = $this->getPaymentFeeLine();
if ($line) {
$line = $this->addLineType($line,static::LineType_PaymentFee, Api::Nature_Service);
$result[] = $line;
}
$line = $this->getGiftWrappingLine();
if ($line) {
$line = $this->addLineType($line,static::LineType_GiftWrapping, Api::Nature_Service);
$result[] = $line;
}
return $result;
} | [
"protected",
"function",
"getFeeLines",
"(",
")",
"{",
"$",
"result",
"=",
"array",
"(",
")",
";",
"$",
"shippingLines",
"=",
"$",
"this",
"->",
"getShippingLines",
"(",
")",
";",
"if",
"(",
"$",
"shippingLines",
")",
"{",
"$",
"shippingLines",
"=",
"$... | Returns all the fee lines for the order.
Override this method if it is easier to return all fee lines at once.
If you do so, you are responsible for adding the line Meta::LineType meta
data. Otherwise, override the methods getShippingLines() (or
getShippingLine()), getPaymentFeeLine() (if applicable), and
getGiftWrappingLine() (if available).
@return array[]
A, possibly empty, array of fee line arrays. | [
"Returns",
"all",
"the",
"fee",
"lines",
"for",
"the",
"order",
"."
] | 82f8d6c9c4929c41948c97d6cfdfac3f27c37255 | https://github.com/SIELOnline/libAcumulus/blob/82f8d6c9c4929c41948c97d6cfdfac3f27c37255/src/Invoice/Creator.php#L671-L694 | train |
SIELOnline/libAcumulus | src/Invoice/Creator.php | Creator.addTokenDefault | protected function addTokenDefault(array &$array, $key, $token)
{
if (empty($array[$key]) && !empty($token)) {
$value = $this->getTokenizedValue($token);
if (!empty($value)) {
$array[$key] = $value;
return true;
}
}
return false;
} | php | protected function addTokenDefault(array &$array, $key, $token)
{
if (empty($array[$key]) && !empty($token)) {
$value = $this->getTokenizedValue($token);
if (!empty($value)) {
$array[$key] = $value;
return true;
}
}
return false;
} | [
"protected",
"function",
"addTokenDefault",
"(",
"array",
"&",
"$",
"array",
",",
"$",
"key",
",",
"$",
"token",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"array",
"[",
"$",
"key",
"]",
")",
"&&",
"!",
"empty",
"(",
"$",
"token",
")",
")",
"{",
"... | Helper method to add a non-empty possibly tokenized value to an array.
This method will not overwrite existing values.
@param array $array
@param string $key
@param string $token
String value that may contain token definitions.
@return bool
Whether the default was added. | [
"Helper",
"method",
"to",
"add",
"a",
"non",
"-",
"empty",
"possibly",
"tokenized",
"value",
"to",
"an",
"array",
"."
] | 82f8d6c9c4929c41948c97d6cfdfac3f27c37255 | https://github.com/SIELOnline/libAcumulus/blob/82f8d6c9c4929c41948c97d6cfdfac3f27c37255/src/Invoice/Creator.php#L866-L876 | train |
SIELOnline/libAcumulus | src/Invoice/Creator.php | Creator.addIfSetAndNotEmpty | protected function addIfSetAndNotEmpty(array &$targetArray, $targetKey, $source, $sourceKey)
{
if (is_array($source)) {
if (!empty($source[$sourceKey])) {
$targetArray[$targetKey] = $source[$sourceKey];
return true;
}
} else {
if (!empty($source->$sourceKey)) {
$targetArray[$targetKey] = $source->$sourceKey;
return true;
}
}
return false;
} | php | protected function addIfSetAndNotEmpty(array &$targetArray, $targetKey, $source, $sourceKey)
{
if (is_array($source)) {
if (!empty($source[$sourceKey])) {
$targetArray[$targetKey] = $source[$sourceKey];
return true;
}
} else {
if (!empty($source->$sourceKey)) {
$targetArray[$targetKey] = $source->$sourceKey;
return true;
}
}
return false;
} | [
"protected",
"function",
"addIfSetAndNotEmpty",
"(",
"array",
"&",
"$",
"targetArray",
",",
"$",
"targetKey",
",",
"$",
"source",
",",
"$",
"sourceKey",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"source",
")",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
... | Helper method to add a value from an array or object only if it is set
and not empty.
@param array $targetArray
@param string $targetKey
@param array|object $source
@param string $sourceKey
@return bool
Whether the array value or object property is set and not empty and
thus has been added. | [
"Helper",
"method",
"to",
"add",
"a",
"value",
"from",
"an",
"array",
"or",
"object",
"only",
"if",
"it",
"is",
"set",
"and",
"not",
"empty",
"."
] | 82f8d6c9c4929c41948c97d6cfdfac3f27c37255 | https://github.com/SIELOnline/libAcumulus/blob/82f8d6c9c4929c41948c97d6cfdfac3f27c37255/src/Invoice/Creator.php#L904-L918 | train |
SIELOnline/libAcumulus | src/Invoice/Creator.php | Creator.addEmpty | protected function addEmpty(array &$array, $key, $value, $default = '')
{
if (!empty($value)) {
$array[$key] = $value;
return true;
} else {
$array[$key] = $default;
return false;
}
} | php | protected function addEmpty(array &$array, $key, $value, $default = '')
{
if (!empty($value)) {
$array[$key] = $value;
return true;
} else {
$array[$key] = $default;
return false;
}
} | [
"protected",
"function",
"addEmpty",
"(",
"array",
"&",
"$",
"array",
",",
"$",
"key",
",",
"$",
"value",
",",
"$",
"default",
"=",
"''",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"value",
")",
")",
"{",
"$",
"array",
"[",
"$",
"key",
"]",
... | Helper method to add a value to an array even if it is empty.
@param array $array
@param string $key
@param mixed $value
@param mixed $default
@return bool
True if the value was not empty and thus has been added, false if the
default has been added. | [
"Helper",
"method",
"to",
"add",
"a",
"value",
"to",
"an",
"array",
"even",
"if",
"it",
"is",
"empty",
"."
] | 82f8d6c9c4929c41948c97d6cfdfac3f27c37255 | https://github.com/SIELOnline/libAcumulus/blob/82f8d6c9c4929c41948c97d6cfdfac3f27c37255/src/Invoice/Creator.php#L952-L961 | train |
SIELOnline/libAcumulus | src/Invoice/Creator.php | Creator.getVatRangeTags | public static function getVatRangeTags($numerator, $denominator, $numeratorPrecision = 0.01, $denominatorPrecision = 0.01)
{
if (Number::isZero($denominator, 0.0001)) {
$result = array(
Tag::VatRate => null,
Meta::VatAmount => $numerator,
Meta::VatRateSource => static::VatRateSource_Completor,
);
} elseif (Number::isZero($numerator, 0.0001)) {
$result = array(
Tag::VatRate => 0,
Meta::VatAmount => $numerator,
Meta::VatRateSource => static::VatRateSource_Exact0,
);
} else {
$range = Number::getDivisionRange($numerator, $denominator, $numeratorPrecision, $denominatorPrecision);
$result = array(
Tag::VatRate => 100.0 * $range['calculated'],
Meta::VatRateMin => 100.0 * $range['min'],
Meta::VatRateMax => 100.0 * $range['max'],
Meta::VatAmount => $numerator,
Meta::PrecisionUnitPrice => $denominatorPrecision,
Meta::PrecisionVatAmount => $numeratorPrecision,
Meta::VatRateSource => static::VatRateSource_Calculated,
);
}
return $result;
} | php | public static function getVatRangeTags($numerator, $denominator, $numeratorPrecision = 0.01, $denominatorPrecision = 0.01)
{
if (Number::isZero($denominator, 0.0001)) {
$result = array(
Tag::VatRate => null,
Meta::VatAmount => $numerator,
Meta::VatRateSource => static::VatRateSource_Completor,
);
} elseif (Number::isZero($numerator, 0.0001)) {
$result = array(
Tag::VatRate => 0,
Meta::VatAmount => $numerator,
Meta::VatRateSource => static::VatRateSource_Exact0,
);
} else {
$range = Number::getDivisionRange($numerator, $denominator, $numeratorPrecision, $denominatorPrecision);
$result = array(
Tag::VatRate => 100.0 * $range['calculated'],
Meta::VatRateMin => 100.0 * $range['min'],
Meta::VatRateMax => 100.0 * $range['max'],
Meta::VatAmount => $numerator,
Meta::PrecisionUnitPrice => $denominatorPrecision,
Meta::PrecisionVatAmount => $numeratorPrecision,
Meta::VatRateSource => static::VatRateSource_Calculated,
);
}
return $result;
} | [
"public",
"static",
"function",
"getVatRangeTags",
"(",
"$",
"numerator",
",",
"$",
"denominator",
",",
"$",
"numeratorPrecision",
"=",
"0.01",
",",
"$",
"denominatorPrecision",
"=",
"0.01",
")",
"{",
"if",
"(",
"Number",
"::",
"isZero",
"(",
"$",
"denominat... | Returns the range in which the vat rate will lie.
If a webshop does not store the vat rates used in the order, we must
calculate them using a (product) price and the vat on it. But as web
shops often store these numbers rounded to cents, the vat rate
calculation becomes imprecise. Therefore we compute the range in which
it will lie and will let the Completor do a comparison with the actual
vat rates that an order can have (one of the Dutch or, for electronic
services, other EU country VAT rates).
- If $denominator = 0 (free product), the vatrate will be set to null
and the Completor will try to get this line listed under the correct
vat rate.
- If $numerator = 0 the vatrate will be set to 0 and be treated as if it
is an exact vat rate, not a vat range.
@param float $numerator
The amount of VAT as received from the web shop.
@param float $denominator
The price of a product excluding VAT as received from the web shop.
@param float $numeratorPrecision
The precision used when rounding the number. This means that the
original numerator will not differ more than half of this.
@param float $denominatorPrecision
The precision used when rounding the number. This means that the
original denominator will not differ more than half of this.
@return array
Array with keys (noy all keys will always be available):
- vatrate
- vatamount
- meta-vatrate-min
- meta-vatrate-max
- meta-vatamount-precision
- meta-vatrate-source
@todo: can we move this from the (plugin specific) creators to the
completor phase? This would aid in simplifying the creators towards raw
data collectors.. | [
"Returns",
"the",
"range",
"in",
"which",
"the",
"vat",
"rate",
"will",
"lie",
"."
] | 82f8d6c9c4929c41948c97d6cfdfac3f27c37255 | https://github.com/SIELOnline/libAcumulus/blob/82f8d6c9c4929c41948c97d6cfdfac3f27c37255/src/Invoice/Creator.php#L1085-L1112 | train |
SIELOnline/libAcumulus | src/Invoice/Creator.php | Creator.callSourceTypeSpecificMethod | protected function callSourceTypeSpecificMethod($method, $args = array())
{
$method .= $this->invoiceSource->getType();
return call_user_func_array(array($this, $method), $args);
} | php | protected function callSourceTypeSpecificMethod($method, $args = array())
{
$method .= $this->invoiceSource->getType();
return call_user_func_array(array($this, $method), $args);
} | [
"protected",
"function",
"callSourceTypeSpecificMethod",
"(",
"$",
"method",
",",
"$",
"args",
"=",
"array",
"(",
")",
")",
"{",
"$",
"method",
".=",
"$",
"this",
"->",
"invoiceSource",
"->",
"getType",
"(",
")",
";",
"return",
"call_user_func_array",
"(",
... | Calls a method constructed of the method name and the source type.
If the implementation/override of a method depends on the type of invoice
source it might be better to implement 1 method per source type. This
method calls such a method assuming it is named {method}{source-type}.
Example: if getLineItem($line) would be very different for an order
versus a credit note: do not override the base method but implement 2 new
methods getLineItemOrder($line) and getLineItemCreditNote($line).
@param string $method
@param array $args
@return mixed | [
"Calls",
"a",
"method",
"constructed",
"of",
"the",
"method",
"name",
"and",
"the",
"source",
"type",
"."
] | 82f8d6c9c4929c41948c97d6cfdfac3f27c37255 | https://github.com/SIELOnline/libAcumulus/blob/82f8d6c9c4929c41948c97d6cfdfac3f27c37255/src/Invoice/Creator.php#L1129-L1133 | train |
ipunkt/rancherize | app/Configuration/Services/ProjectConfiguration.php | ProjectConfiguration.save | public function save( Configuration $configuration ) {
/**
* Only values under the `project` key should be written to the project config
*/
$prefixDecorator = new PrefixConfigurableDecorator( $configuration, 'project' );
$rancherizePath = $this->getConfigPath();
$this->writer->write( $prefixDecorator, $rancherizePath );
} | php | public function save( Configuration $configuration ) {
/**
* Only values under the `project` key should be written to the project config
*/
$prefixDecorator = new PrefixConfigurableDecorator( $configuration, 'project' );
$rancherizePath = $this->getConfigPath();
$this->writer->write( $prefixDecorator, $rancherizePath );
} | [
"public",
"function",
"save",
"(",
"Configuration",
"$",
"configuration",
")",
"{",
"/**\n\t\t * Only values under the `project` key should be written to the project config\n\t\t */",
"$",
"prefixDecorator",
"=",
"new",
"PrefixConfigurableDecorator",
"(",
"$",
"configuration",
",... | Save the project part of the configuration
@param Configuration $configuration | [
"Save",
"the",
"project",
"part",
"of",
"the",
"configuration"
] | 3c226da686b283e7fef961a9a79b54db53b8757b | https://github.com/ipunkt/rancherize/blob/3c226da686b283e7fef961a9a79b54db53b8757b/app/Configuration/Services/ProjectConfiguration.php#L74-L85 | train |
ipunkt/rancherize | app/File/FileLoader.php | FileLoader.get | public function get(string $path) : string {
if(! file_exists($path) )
throw new FileNotFoundException($path, 200);
return file_get_contents($path);
} | php | public function get(string $path) : string {
if(! file_exists($path) )
throw new FileNotFoundException($path, 200);
return file_get_contents($path);
} | [
"public",
"function",
"get",
"(",
"string",
"$",
"path",
")",
":",
"string",
"{",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"path",
")",
")",
"throw",
"new",
"FileNotFoundException",
"(",
"$",
"path",
",",
"200",
")",
";",
"return",
"file_get_contents",
... | Load file from disk
@param $path
@return string | [
"Load",
"file",
"from",
"disk"
] | 3c226da686b283e7fef961a9a79b54db53b8757b | https://github.com/ipunkt/rancherize/blob/3c226da686b283e7fef961a9a79b54db53b8757b/app/File/FileLoader.php#L18-L24 | train |
SIELOnline/libAcumulus | src/Helpers/Log.php | Log.getSeverityString | protected function getSeverityString($severity)
{
switch ($severity) {
case Log::Error:
return 'Error';
case Log::Warning:
return 'Warning';
case Log::Notice:
return 'Notice';
case Log::Info:
return 'Info';
case Log::Debug:
default:
return 'Debug';
}
} | php | protected function getSeverityString($severity)
{
switch ($severity) {
case Log::Error:
return 'Error';
case Log::Warning:
return 'Warning';
case Log::Notice:
return 'Notice';
case Log::Info:
return 'Info';
case Log::Debug:
default:
return 'Debug';
}
} | [
"protected",
"function",
"getSeverityString",
"(",
"$",
"severity",
")",
"{",
"switch",
"(",
"$",
"severity",
")",
"{",
"case",
"Log",
"::",
"Error",
":",
"return",
"'Error'",
";",
"case",
"Log",
"::",
"Warning",
":",
"return",
"'Warning'",
";",
"case",
... | Returns a textual representation of the severity.
@param int $severity
One of the constants of this class.
@return string
A textual representation of the severity. | [
"Returns",
"a",
"textual",
"representation",
"of",
"the",
"severity",
"."
] | 82f8d6c9c4929c41948c97d6cfdfac3f27c37255 | https://github.com/SIELOnline/libAcumulus/blob/82f8d6c9c4929c41948c97d6cfdfac3f27c37255/src/Helpers/Log.php#L74-L89 | train |
SIELOnline/libAcumulus | src/Helpers/Log.php | Log.log | public function log($severity, $message, array $args = array())
{
if ($severity <= max($this->getLogLevel(), Log::Warning)) {
if (count($args) > 0) {
$message = vsprintf($message, $args);
}
$this->write($message, $severity);
}
return $message;
} | php | public function log($severity, $message, array $args = array())
{
if ($severity <= max($this->getLogLevel(), Log::Warning)) {
if (count($args) > 0) {
$message = vsprintf($message, $args);
}
$this->write($message, $severity);
}
return $message;
} | [
"public",
"function",
"log",
"(",
"$",
"severity",
",",
"$",
"message",
",",
"array",
"$",
"args",
"=",
"array",
"(",
")",
")",
"{",
"if",
"(",
"$",
"severity",
"<=",
"max",
"(",
"$",
"this",
"->",
"getLogLevel",
"(",
")",
",",
"Log",
"::",
"Warn... | Formats and logs the message if the log level indicates so.
Errors and Warnings are always logged, other levels only if the log level
is set to do so.
Formatting involves:
- calling vsprintf() if $args is not empty
- adding "Acumulus {version} {severity}: " in front of the message.
@param int $severity
@param string $message
@param array $args
@return string
The full formatted message whether it got logged or not. | [
"Formats",
"and",
"logs",
"the",
"message",
"if",
"the",
"log",
"level",
"indicates",
"so",
"."
] | 82f8d6c9c4929c41948c97d6cfdfac3f27c37255 | https://github.com/SIELOnline/libAcumulus/blob/82f8d6c9c4929c41948c97d6cfdfac3f27c37255/src/Helpers/Log.php#L108-L117 | train |
SIELOnline/libAcumulus | src/Helpers/Log.php | Log.notice | public function notice($message)
{
$args = func_get_args();
array_shift($args);
return $this->log(Log::Notice, $message, $args);
} | php | public function notice($message)
{
$args = func_get_args();
array_shift($args);
return $this->log(Log::Notice, $message, $args);
} | [
"public",
"function",
"notice",
"(",
"$",
"message",
")",
"{",
"$",
"args",
"=",
"func_get_args",
"(",
")",
";",
"array_shift",
"(",
"$",
"args",
")",
";",
"return",
"$",
"this",
"->",
"log",
"(",
"Log",
"::",
"Notice",
",",
"$",
"message",
",",
"$... | Logs a notice.
@param string $message,...
The message to log, optionally followed by arguments. If there are
arguments the $message is passed through vsprintf().
@return string
The full formatted message whether it got logged or not. | [
"Logs",
"a",
"notice",
"."
] | 82f8d6c9c4929c41948c97d6cfdfac3f27c37255 | https://github.com/SIELOnline/libAcumulus/blob/82f8d6c9c4929c41948c97d6cfdfac3f27c37255/src/Helpers/Log.php#L146-L151 | train |
SIELOnline/libAcumulus | src/Helpers/Log.php | Log.info | public function info($message)
{
$args = func_get_args();
array_shift($args);
return $this->log(Log::Info, $message, $args);
} | php | public function info($message)
{
$args = func_get_args();
array_shift($args);
return $this->log(Log::Info, $message, $args);
} | [
"public",
"function",
"info",
"(",
"$",
"message",
")",
"{",
"$",
"args",
"=",
"func_get_args",
"(",
")",
";",
"array_shift",
"(",
"$",
"args",
")",
";",
"return",
"$",
"this",
"->",
"log",
"(",
"Log",
"::",
"Info",
",",
"$",
"message",
",",
"$",
... | Logs an informational message.
@param string $message,...
The message to log, optionally followed by arguments. If there are
arguments the $message is passed through vsprintf().
@return string
The full formatted message whether it got logged or not. | [
"Logs",
"an",
"informational",
"message",
"."
] | 82f8d6c9c4929c41948c97d6cfdfac3f27c37255 | https://github.com/SIELOnline/libAcumulus/blob/82f8d6c9c4929c41948c97d6cfdfac3f27c37255/src/Helpers/Log.php#L163-L168 | train |
SIELOnline/libAcumulus | src/Helpers/Log.php | Log.warning | public function warning($message)
{
$args = func_get_args();
array_shift($args);
return $this->log(Log::Warning, $message, $args);
} | php | public function warning($message)
{
$args = func_get_args();
array_shift($args);
return $this->log(Log::Warning, $message, $args);
} | [
"public",
"function",
"warning",
"(",
"$",
"message",
")",
"{",
"$",
"args",
"=",
"func_get_args",
"(",
")",
";",
"array_shift",
"(",
"$",
"args",
")",
";",
"return",
"$",
"this",
"->",
"log",
"(",
"Log",
"::",
"Warning",
",",
"$",
"message",
",",
... | Logs a warning.
@param string $message,...
The message to log, optionally followed by arguments. If there are
arguments the $message is passed through vsprintf().
@return string
The full formatted message whether it got logged or not. | [
"Logs",
"a",
"warning",
"."
] | 82f8d6c9c4929c41948c97d6cfdfac3f27c37255 | https://github.com/SIELOnline/libAcumulus/blob/82f8d6c9c4929c41948c97d6cfdfac3f27c37255/src/Helpers/Log.php#L180-L185 | train |
SIELOnline/libAcumulus | src/Helpers/Log.php | Log.write | protected function write($message, $severity)
{
$message = sprintf('Acumulus %s: %s - %s', $this->getLibraryVersion(), $this->getSeverityString($severity), $message);
error_log($message);
} | php | protected function write($message, $severity)
{
$message = sprintf('Acumulus %s: %s - %s', $this->getLibraryVersion(), $this->getSeverityString($severity), $message);
error_log($message);
} | [
"protected",
"function",
"write",
"(",
"$",
"message",
",",
"$",
"severity",
")",
"{",
"$",
"message",
"=",
"sprintf",
"(",
"'Acumulus %s: %s - %s'",
",",
"$",
"this",
"->",
"getLibraryVersion",
"(",
")",
",",
"$",
"this",
"->",
"getSeverityString",
"(",
"... | Writes the message to the actual log sink.
This base implementation adds the name Acumulus, the version of this
library, and the severity and then sends the message to error_log().
Override if the web shop offers its own log mechanism.
@param string $message
@param int $severity | [
"Writes",
"the",
"message",
"to",
"the",
"actual",
"log",
"sink",
"."
] | 82f8d6c9c4929c41948c97d6cfdfac3f27c37255 | https://github.com/SIELOnline/libAcumulus/blob/82f8d6c9c4929c41948c97d6cfdfac3f27c37255/src/Helpers/Log.php#L215-L219 | train |
dreamfactorysoftware/df-user | src/Components/AlternateAuth.php | AlternateAuth.handleLogin | public function handleLogin($request)
{
$filterString = $this->generateFilter($request);
$remoteUser = $this->getRemoteUser($filterString);
$password = $request->input($this->passwordField);
$passwordHash = array_get($remoteUser, $this->passwordField);
if ($this->verifyPassword($password, $passwordHash)) {
$user = $this->createShadowUser($remoteUser);
$forever = $request->input(static::REMEMBER_ME);
$appId = Session::get('app.id');
Session::setUserInfoWithJWT($user, $forever, $appId);
return Session::getPublicInfo();
} else {
throw new UnauthorizedException('Invalid credential supplied.');
}
} | php | public function handleLogin($request)
{
$filterString = $this->generateFilter($request);
$remoteUser = $this->getRemoteUser($filterString);
$password = $request->input($this->passwordField);
$passwordHash = array_get($remoteUser, $this->passwordField);
if ($this->verifyPassword($password, $passwordHash)) {
$user = $this->createShadowUser($remoteUser);
$forever = $request->input(static::REMEMBER_ME);
$appId = Session::get('app.id');
Session::setUserInfoWithJWT($user, $forever, $appId);
return Session::getPublicInfo();
} else {
throw new UnauthorizedException('Invalid credential supplied.');
}
} | [
"public",
"function",
"handleLogin",
"(",
"$",
"request",
")",
"{",
"$",
"filterString",
"=",
"$",
"this",
"->",
"generateFilter",
"(",
"$",
"request",
")",
";",
"$",
"remoteUser",
"=",
"$",
"this",
"->",
"getRemoteUser",
"(",
"$",
"filterString",
")",
"... | Handles login action including creating shadow user if needed
@param \DreamFactory\Core\Contracts\ServiceRequestInterface $request
@return array
@throws \DreamFactory\Core\Exceptions\InternalServerErrorException
@throws \DreamFactory\Core\Exceptions\RestException
@throws \DreamFactory\Core\Exceptions\UnauthorizedException
@throws \Exception | [
"Handles",
"login",
"action",
"including",
"creating",
"shadow",
"user",
"if",
"needed"
] | 06747c83f03d51693d212d948dd5d49f098192ca | https://github.com/dreamfactorysoftware/df-user/blob/06747c83f03d51693d212d948dd5d49f098192ca/src/Components/AlternateAuth.php#L71-L88 | train |
dreamfactorysoftware/df-user | src/Components/AlternateAuth.php | AlternateAuth.generateFilter | protected function generateFilter($request)
{
$this->filters[$this->usernameField] = trim($request->input($this->usernameField));
foreach ($this->otherFields as $of) {
$of = trim($of);
$this->filters[$of] = $request->input($of);
}
$string = '';
$multiple = 0;
foreach ($this->filters as $f => $v) {
if (!empty($string)) {
$string .= " AND ";
$multiple = 1;
}
if (is_bool($v) || 'true' === strtolower($v) || 'false' === strtolower($v)) {
if ($v === true || $v === 'true') {
$v = 1;
} else {
$v = 0;
}
}
$string .= "($f=$v)";
}
return ($multiple) ? "(" . $string . ")" : $string;
} | php | protected function generateFilter($request)
{
$this->filters[$this->usernameField] = trim($request->input($this->usernameField));
foreach ($this->otherFields as $of) {
$of = trim($of);
$this->filters[$of] = $request->input($of);
}
$string = '';
$multiple = 0;
foreach ($this->filters as $f => $v) {
if (!empty($string)) {
$string .= " AND ";
$multiple = 1;
}
if (is_bool($v) || 'true' === strtolower($v) || 'false' === strtolower($v)) {
if ($v === true || $v === 'true') {
$v = 1;
} else {
$v = 0;
}
}
$string .= "($f=$v)";
}
return ($multiple) ? "(" . $string . ")" : $string;
} | [
"protected",
"function",
"generateFilter",
"(",
"$",
"request",
")",
"{",
"$",
"this",
"->",
"filters",
"[",
"$",
"this",
"->",
"usernameField",
"]",
"=",
"trim",
"(",
"$",
"request",
"->",
"input",
"(",
"$",
"this",
"->",
"usernameField",
")",
")",
";... | Generates filter string based on request parameter and configured options
@param \DreamFactory\Core\Contracts\ServiceRequestInterface $request
@return string | [
"Generates",
"filter",
"string",
"based",
"on",
"request",
"parameter",
"and",
"configured",
"options"
] | 06747c83f03d51693d212d948dd5d49f098192ca | https://github.com/dreamfactorysoftware/df-user/blob/06747c83f03d51693d212d948dd5d49f098192ca/src/Components/AlternateAuth.php#L97-L123 | train |
dreamfactorysoftware/df-user | src/Components/AlternateAuth.php | AlternateAuth.getRemoteUser | protected function getRemoteUser($filter)
{
$resource = '_table/' . $this->table;
$response = ServiceManager::handleRequest(
$this->service,
Verbs::GET,
$resource,
['filter' => $filter],
[], null, null, false
);
$status = $response->getStatusCode();
if ($status === 200) {
$result = ResourcesWrapper::unwrapResources($response->getContent());
if (!Arr::isAssoc($result)) {
if (count($result) > 1) {
throw new InternalServerErrorException('An unexpected error occurred. More than one user found with your credentials!');
}
if (count($result) === 0) {
throw new UnauthorizedException('Invalid user information provided.');
}
$result = $result[0];
}
return $result;
} else {
$message = 'DB service responded with code ' . $status;
if ($status >= 400) {
$content = $response->getContent();
$message = array_get($content, 'error.message', $message);
} else {
$status = 500;
}
throw new RestException($status, $message);
}
} | php | protected function getRemoteUser($filter)
{
$resource = '_table/' . $this->table;
$response = ServiceManager::handleRequest(
$this->service,
Verbs::GET,
$resource,
['filter' => $filter],
[], null, null, false
);
$status = $response->getStatusCode();
if ($status === 200) {
$result = ResourcesWrapper::unwrapResources($response->getContent());
if (!Arr::isAssoc($result)) {
if (count($result) > 1) {
throw new InternalServerErrorException('An unexpected error occurred. More than one user found with your credentials!');
}
if (count($result) === 0) {
throw new UnauthorizedException('Invalid user information provided.');
}
$result = $result[0];
}
return $result;
} else {
$message = 'DB service responded with code ' . $status;
if ($status >= 400) {
$content = $response->getContent();
$message = array_get($content, 'error.message', $message);
} else {
$status = 500;
}
throw new RestException($status, $message);
}
} | [
"protected",
"function",
"getRemoteUser",
"(",
"$",
"filter",
")",
"{",
"$",
"resource",
"=",
"'_table/'",
".",
"$",
"this",
"->",
"table",
";",
"$",
"response",
"=",
"ServiceManager",
"::",
"handleRequest",
"(",
"$",
"this",
"->",
"service",
",",
"Verbs",... | Retrieves the user from remote source
@param $filter
@return mixed
@throws \DreamFactory\Core\Exceptions\BadRequestException
@throws \DreamFactory\Core\Exceptions\InternalServerErrorException
@throws \DreamFactory\Core\Exceptions\RestException
@throws \DreamFactory\Core\Exceptions\UnauthorizedException
@throws \Exception | [
"Retrieves",
"the",
"user",
"from",
"remote",
"source"
] | 06747c83f03d51693d212d948dd5d49f098192ca | https://github.com/dreamfactorysoftware/df-user/blob/06747c83f03d51693d212d948dd5d49f098192ca/src/Components/AlternateAuth.php#L137-L172 | train |
dreamfactorysoftware/df-user | src/Components/AlternateAuth.php | AlternateAuth.verifyPassword | protected function verifyPassword($password, $hash)
{
// Check plain password.
if($password === $hash){
return true;
}
// Check md5 hash
if (md5($password) === $hash) {
return true;
}
// Check bcrypt hash
return password_verify($password, $hash);
} | php | protected function verifyPassword($password, $hash)
{
// Check plain password.
if($password === $hash){
return true;
}
// Check md5 hash
if (md5($password) === $hash) {
return true;
}
// Check bcrypt hash
return password_verify($password, $hash);
} | [
"protected",
"function",
"verifyPassword",
"(",
"$",
"password",
",",
"$",
"hash",
")",
"{",
"// Check plain password.",
"if",
"(",
"$",
"password",
"===",
"$",
"hash",
")",
"{",
"return",
"true",
";",
"}",
"// Check md5 hash",
"if",
"(",
"md5",
"(",
"$",
... | Verifies the password hash
@param $password
@param $hash
@return bool | [
"Verifies",
"the",
"password",
"hash"
] | 06747c83f03d51693d212d948dd5d49f098192ca | https://github.com/dreamfactorysoftware/df-user/blob/06747c83f03d51693d212d948dd5d49f098192ca/src/Components/AlternateAuth.php#L182-L194 | train |
dreamfactorysoftware/df-user | src/Components/AlternateAuth.php | AlternateAuth.createShadowUser | protected function createShadowUser($userInfo)
{
$email = filter_var(array_get($userInfo, $this->emailField), FILTER_SANITIZE_EMAIL);
if (empty($email)) {
throw new InternalServerErrorException(
'Failed to retrieve alternate user\'s email address using field ' . $this->emailField . '.'
);
}
$dfUser = User::whereEmail($email)->first();
if (empty($dfUser)) {
$altUser = [
'email' => $email,
'first_name' => 'Alternate',
'last_name' => 'User',
'name' => 'Alternate User'
];
$dfUser = User::create($altUser);
}
return $dfUser;
} | php | protected function createShadowUser($userInfo)
{
$email = filter_var(array_get($userInfo, $this->emailField), FILTER_SANITIZE_EMAIL);
if (empty($email)) {
throw new InternalServerErrorException(
'Failed to retrieve alternate user\'s email address using field ' . $this->emailField . '.'
);
}
$dfUser = User::whereEmail($email)->first();
if (empty($dfUser)) {
$altUser = [
'email' => $email,
'first_name' => 'Alternate',
'last_name' => 'User',
'name' => 'Alternate User'
];
$dfUser = User::create($altUser);
}
return $dfUser;
} | [
"protected",
"function",
"createShadowUser",
"(",
"$",
"userInfo",
")",
"{",
"$",
"email",
"=",
"filter_var",
"(",
"array_get",
"(",
"$",
"userInfo",
",",
"$",
"this",
"->",
"emailField",
")",
",",
"FILTER_SANITIZE_EMAIL",
")",
";",
"if",
"(",
"empty",
"("... | Creates the shadow user if needed
@param array $userInfo
@return \DreamFactory\Core\Models\BaseModel|\Illuminate\Database\Eloquent\Model|null|static
@throws \DreamFactory\Core\Exceptions\InternalServerErrorException
@throws \Exception | [
"Creates",
"the",
"shadow",
"user",
"if",
"needed"
] | 06747c83f03d51693d212d948dd5d49f098192ca | https://github.com/dreamfactorysoftware/df-user/blob/06747c83f03d51693d212d948dd5d49f098192ca/src/Components/AlternateAuth.php#L205-L226 | train |
dreamfactorysoftware/df-user | src/Components/AlternateAuth.php | AlternateAuth.setService | public function setService($id)
{
$id = filter_var($id, FILTER_SANITIZE_NUMBER_INT);
if (empty($id)) {
throw new InternalServerErrorException('No service id provided.');
}
if (empty($this->service = ServiceManager::getServiceNameById($id))) {
throw new InternalServerErrorException('No alternate db service found with id ' . $id);
}
} | php | public function setService($id)
{
$id = filter_var($id, FILTER_SANITIZE_NUMBER_INT);
if (empty($id)) {
throw new InternalServerErrorException('No service id provided.');
}
if (empty($this->service = ServiceManager::getServiceNameById($id))) {
throw new InternalServerErrorException('No alternate db service found with id ' . $id);
}
} | [
"public",
"function",
"setService",
"(",
"$",
"id",
")",
"{",
"$",
"id",
"=",
"filter_var",
"(",
"$",
"id",
",",
"FILTER_SANITIZE_NUMBER_INT",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"id",
")",
")",
"{",
"throw",
"new",
"InternalServerErrorException",
"(... | Sets the db service name
@param integer $id
@throws \DreamFactory\Core\Exceptions\InternalServerErrorException | [
"Sets",
"the",
"db",
"service",
"name"
] | 06747c83f03d51693d212d948dd5d49f098192ca | https://github.com/dreamfactorysoftware/df-user/blob/06747c83f03d51693d212d948dd5d49f098192ca/src/Components/AlternateAuth.php#L235-L245 | train |
dreamfactorysoftware/df-user | src/Components/AlternateAuth.php | AlternateAuth.setTable | public function setTable($table)
{
$table = trim(filter_var($table, FILTER_SANITIZE_STRING));
if (empty($table)) {
throw new InternalServerErrorException('No table name provided.');
}
$this->table = $table;
} | php | public function setTable($table)
{
$table = trim(filter_var($table, FILTER_SANITIZE_STRING));
if (empty($table)) {
throw new InternalServerErrorException('No table name provided.');
}
$this->table = $table;
} | [
"public",
"function",
"setTable",
"(",
"$",
"table",
")",
"{",
"$",
"table",
"=",
"trim",
"(",
"filter_var",
"(",
"$",
"table",
",",
"FILTER_SANITIZE_STRING",
")",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"table",
")",
")",
"{",
"throw",
"new",
"Inter... | Sets the table name
@param string $table
@throws \DreamFactory\Core\Exceptions\InternalServerErrorException | [
"Sets",
"the",
"table",
"name"
] | 06747c83f03d51693d212d948dd5d49f098192ca | https://github.com/dreamfactorysoftware/df-user/blob/06747c83f03d51693d212d948dd5d49f098192ca/src/Components/AlternateAuth.php#L254-L262 | train |
dreamfactorysoftware/df-user | src/Components/AlternateAuth.php | AlternateAuth.setUsernameField | public function setUsernameField($uf)
{
$uf = trim(filter_var($uf, FILTER_SANITIZE_STRING));
if (empty($uf)) {
throw new InternalServerErrorException('No username field provided.');
}
$this->usernameField = $uf;
} | php | public function setUsernameField($uf)
{
$uf = trim(filter_var($uf, FILTER_SANITIZE_STRING));
if (empty($uf)) {
throw new InternalServerErrorException('No username field provided.');
}
$this->usernameField = $uf;
} | [
"public",
"function",
"setUsernameField",
"(",
"$",
"uf",
")",
"{",
"$",
"uf",
"=",
"trim",
"(",
"filter_var",
"(",
"$",
"uf",
",",
"FILTER_SANITIZE_STRING",
")",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"uf",
")",
")",
"{",
"throw",
"new",
"InternalS... | Sets the username field
@param string $uf
@throws \DreamFactory\Core\Exceptions\InternalServerErrorException | [
"Sets",
"the",
"username",
"field"
] | 06747c83f03d51693d212d948dd5d49f098192ca | https://github.com/dreamfactorysoftware/df-user/blob/06747c83f03d51693d212d948dd5d49f098192ca/src/Components/AlternateAuth.php#L271-L279 | train |
dreamfactorysoftware/df-user | src/Components/AlternateAuth.php | AlternateAuth.setPasswordField | public function setPasswordField($pf)
{
$pf = trim(filter_var($pf, FILTER_SANITIZE_STRING));
if (empty($pf)) {
throw new InternalServerErrorException('No password field provided.');
}
$this->passwordField = $pf;
} | php | public function setPasswordField($pf)
{
$pf = trim(filter_var($pf, FILTER_SANITIZE_STRING));
if (empty($pf)) {
throw new InternalServerErrorException('No password field provided.');
}
$this->passwordField = $pf;
} | [
"public",
"function",
"setPasswordField",
"(",
"$",
"pf",
")",
"{",
"$",
"pf",
"=",
"trim",
"(",
"filter_var",
"(",
"$",
"pf",
",",
"FILTER_SANITIZE_STRING",
")",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"pf",
")",
")",
"{",
"throw",
"new",
"InternalS... | Sets the password field
@param string $pf
@throws \DreamFactory\Core\Exceptions\InternalServerErrorException | [
"Sets",
"the",
"password",
"field"
] | 06747c83f03d51693d212d948dd5d49f098192ca | https://github.com/dreamfactorysoftware/df-user/blob/06747c83f03d51693d212d948dd5d49f098192ca/src/Components/AlternateAuth.php#L288-L296 | train |
dreamfactorysoftware/df-user | src/Components/AlternateAuth.php | AlternateAuth.setEmailField | public function setEmailField($ef)
{
$ef = trim(filter_var($ef, FILTER_SANITIZE_STRING));
if (empty($ef)) {
throw new InternalServerErrorException('No email field provided.');
}
$this->emailField = $ef;
} | php | public function setEmailField($ef)
{
$ef = trim(filter_var($ef, FILTER_SANITIZE_STRING));
if (empty($ef)) {
throw new InternalServerErrorException('No email field provided.');
}
$this->emailField = $ef;
} | [
"public",
"function",
"setEmailField",
"(",
"$",
"ef",
")",
"{",
"$",
"ef",
"=",
"trim",
"(",
"filter_var",
"(",
"$",
"ef",
",",
"FILTER_SANITIZE_STRING",
")",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"ef",
")",
")",
"{",
"throw",
"new",
"InternalServ... | Sets the email field
@param string $ef
@throws \DreamFactory\Core\Exceptions\InternalServerErrorException | [
"Sets",
"the",
"email",
"field"
] | 06747c83f03d51693d212d948dd5d49f098192ca | https://github.com/dreamfactorysoftware/df-user/blob/06747c83f03d51693d212d948dd5d49f098192ca/src/Components/AlternateAuth.php#L305-L313 | train |
dreamfactorysoftware/df-user | src/Components/AlternateAuth.php | AlternateAuth.parseFilters | protected function parseFilters($filters)
{
$parsed = [];
if (!empty($filters) && is_string($filters)) {
$filters = trim($filters);
if (!empty($filters)) {
$filterArray = array_filter(explode(',', $filters), function ($value){
return trim($value);
});
foreach ($filterArray as $filter) {
list($field, $value) = explode('=', $filter);
$field = trim($field);
$value = trim($value);
if (!empty($field)) {
$parsed[$field] = $value;
}
}
}
}
return $parsed;
} | php | protected function parseFilters($filters)
{
$parsed = [];
if (!empty($filters) && is_string($filters)) {
$filters = trim($filters);
if (!empty($filters)) {
$filterArray = array_filter(explode(',', $filters), function ($value){
return trim($value);
});
foreach ($filterArray as $filter) {
list($field, $value) = explode('=', $filter);
$field = trim($field);
$value = trim($value);
if (!empty($field)) {
$parsed[$field] = $value;
}
}
}
}
return $parsed;
} | [
"protected",
"function",
"parseFilters",
"(",
"$",
"filters",
")",
"{",
"$",
"parsed",
"=",
"[",
"]",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"filters",
")",
"&&",
"is_string",
"(",
"$",
"filters",
")",
")",
"{",
"$",
"filters",
"=",
"trim",
"(",
... | Parses filter string
@param string $filters
@return array | [
"Parses",
"filter",
"string"
] | 06747c83f03d51693d212d948dd5d49f098192ca | https://github.com/dreamfactorysoftware/df-user/blob/06747c83f03d51693d212d948dd5d49f098192ca/src/Components/AlternateAuth.php#L356-L378 | train |
ICEPAY/deprecated-i | src/icepay_api_pbm.php | Icepay_Api_Pbm.createLink | public function createLink(Icepay_Pbm_Object $pbmObject)
{
$this->validateSettings();
$linkObj = new StdClass();
$linkObj->merchantid = $this->getMerchantID();
$linkObj->timestamp = $this->getTimestamp();
$linkObj->amount = $pbmObject->getAmount();
$linkObj->currency = $pbmObject->getCurrency();
$linkObj->language = $pbmObject->getLanguage();
$linkObj->orderid = $pbmObject->getOrderID();
$linkObj->country = $pbmObject->getCountry();
$linkObj->description = $pbmObject->getDescription();
$linkObj->reference = $pbmObject->getReference();
$linkObj->checksum = $this->generateChecksum($linkObj);
$result = $this->generateURL($linkObj);
return json_decode($result);
} | php | public function createLink(Icepay_Pbm_Object $pbmObject)
{
$this->validateSettings();
$linkObj = new StdClass();
$linkObj->merchantid = $this->getMerchantID();
$linkObj->timestamp = $this->getTimestamp();
$linkObj->amount = $pbmObject->getAmount();
$linkObj->currency = $pbmObject->getCurrency();
$linkObj->language = $pbmObject->getLanguage();
$linkObj->orderid = $pbmObject->getOrderID();
$linkObj->country = $pbmObject->getCountry();
$linkObj->description = $pbmObject->getDescription();
$linkObj->reference = $pbmObject->getReference();
$linkObj->checksum = $this->generateChecksum($linkObj);
$result = $this->generateURL($linkObj);
return json_decode($result);
} | [
"public",
"function",
"createLink",
"(",
"Icepay_Pbm_Object",
"$",
"pbmObject",
")",
"{",
"$",
"this",
"->",
"validateSettings",
"(",
")",
";",
"$",
"linkObj",
"=",
"new",
"StdClass",
"(",
")",
";",
"$",
"linkObj",
"->",
"merchantid",
"=",
"$",
"this",
"... | Create a PBM link
@since 1.0.0
@param Icepay_Pbm_Object $pbmObject
@return string | [
"Create",
"a",
"PBM",
"link"
] | 9a22271dfaea7f318a555c00d7e3f8cca9f2a28e | https://github.com/ICEPAY/deprecated-i/blob/9a22271dfaea7f318a555c00d7e3f8cca9f2a28e/src/icepay_api_pbm.php#L78-L97 | train |
ICEPAY/deprecated-i | src/icepay_api_pbm.php | Icepay_Api_Pbm.generateURL | private function generateURL($parameters)
{
$ch = curl_init();
$parameters = http_build_query($parameters);
curl_setopt($ch, CURLOPT_URL, $this->url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $parameters);
$result = curl_exec($ch);
curl_close($ch);
return $result;
} | php | private function generateURL($parameters)
{
$ch = curl_init();
$parameters = http_build_query($parameters);
curl_setopt($ch, CURLOPT_URL, $this->url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $parameters);
$result = curl_exec($ch);
curl_close($ch);
return $result;
} | [
"private",
"function",
"generateURL",
"(",
"$",
"parameters",
")",
"{",
"$",
"ch",
"=",
"curl_init",
"(",
")",
";",
"$",
"parameters",
"=",
"http_build_query",
"(",
"$",
"parameters",
")",
";",
"curl_setopt",
"(",
"$",
"ch",
",",
"CURLOPT_URL",
",",
"$",... | Calls PBM platform and returns generated PBM link
@since 1.0.0
@param object $parameters
@return string | [
"Calls",
"PBM",
"platform",
"and",
"returns",
"generated",
"PBM",
"link"
] | 9a22271dfaea7f318a555c00d7e3f8cca9f2a28e | https://github.com/ICEPAY/deprecated-i/blob/9a22271dfaea7f318a555c00d7e3f8cca9f2a28e/src/icepay_api_pbm.php#L106-L122 | train |
ICEPAY/deprecated-i | src/icepay_api_pbm.php | Icepay_Api_Pbm.generateChecksum | private function generateChecksum($linkObj)
{
$arr = (array)$linkObj;
$arr[] = $this->getSecretCode();
return sha1(implode("|", $arr));
} | php | private function generateChecksum($linkObj)
{
$arr = (array)$linkObj;
$arr[] = $this->getSecretCode();
return sha1(implode("|", $arr));
} | [
"private",
"function",
"generateChecksum",
"(",
"$",
"linkObj",
")",
"{",
"$",
"arr",
"=",
"(",
"array",
")",
"$",
"linkObj",
";",
"$",
"arr",
"[",
"]",
"=",
"$",
"this",
"->",
"getSecretCode",
"(",
")",
";",
"return",
"sha1",
"(",
"implode",
"(",
... | Generates PBM checksum
@since 1.0.0
@param obj $linkObj
@return string | [
"Generates",
"PBM",
"checksum"
] | 9a22271dfaea7f318a555c00d7e3f8cca9f2a28e | https://github.com/ICEPAY/deprecated-i/blob/9a22271dfaea7f318a555c00d7e3f8cca9f2a28e/src/icepay_api_pbm.php#L131-L137 | train |
ICEPAY/deprecated-i | src/icepay_api_pbm.php | Icepay_Api_Pbm.validateSettings | private function validateSettings()
{
// Validate Merchant ID
if (!Icepay_Parameter_Validation::merchantID($this->getMerchantID()))
throw new Exception('Merchant ID not set, use the setMerchantID() method', 1001);
// Validate SecretCode
if (!Icepay_Parameter_Validation::secretCode($this->getSecretCode()))
throw new Exception('Secretcode ID not set, use the setSecretCode() method', 1002);
} | php | private function validateSettings()
{
// Validate Merchant ID
if (!Icepay_Parameter_Validation::merchantID($this->getMerchantID()))
throw new Exception('Merchant ID not set, use the setMerchantID() method', 1001);
// Validate SecretCode
if (!Icepay_Parameter_Validation::secretCode($this->getSecretCode()))
throw new Exception('Secretcode ID not set, use the setSecretCode() method', 1002);
} | [
"private",
"function",
"validateSettings",
"(",
")",
"{",
"// Validate Merchant ID",
"if",
"(",
"!",
"Icepay_Parameter_Validation",
"::",
"merchantID",
"(",
"$",
"this",
"->",
"getMerchantID",
"(",
")",
")",
")",
"throw",
"new",
"Exception",
"(",
"'Merchant ID not... | Validate the merchant settings
@since 1.0.0
@throws Exception | [
"Validate",
"the",
"merchant",
"settings"
] | 9a22271dfaea7f318a555c00d7e3f8cca9f2a28e | https://github.com/ICEPAY/deprecated-i/blob/9a22271dfaea7f318a555c00d7e3f8cca9f2a28e/src/icepay_api_pbm.php#L145-L154 | train |
SIELOnline/libAcumulus | src/Invoice/CompletorStrategyBase.php | CompletorStrategyBase.getName | public function getName()
{
$nsClass = get_class($this);
$nsClass = substr($nsClass, strrpos($nsClass, '\\') + 1);
return $nsClass;
} | php | public function getName()
{
$nsClass = get_class($this);
$nsClass = substr($nsClass, strrpos($nsClass, '\\') + 1);
return $nsClass;
} | [
"public",
"function",
"getName",
"(",
")",
"{",
"$",
"nsClass",
"=",
"get_class",
"(",
"$",
"this",
")",
";",
"$",
"nsClass",
"=",
"substr",
"(",
"$",
"nsClass",
",",
"strrpos",
"(",
"$",
"nsClass",
",",
"'\\\\'",
")",
"+",
"1",
")",
";",
"return",... | Returns the non namespaced name of the current strategy.
@return string | [
"Returns",
"the",
"non",
"namespaced",
"name",
"of",
"the",
"current",
"strategy",
"."
] | 82f8d6c9c4929c41948c97d6cfdfac3f27c37255 | https://github.com/SIELOnline/libAcumulus/blob/82f8d6c9c4929c41948c97d6cfdfac3f27c37255/src/Invoice/CompletorStrategyBase.php#L134-L139 | train |
SIELOnline/libAcumulus | src/Invoice/CompletorStrategyBase.php | CompletorStrategyBase.initAmounts | protected function initAmounts()
{
$invoicePart = &$this->invoice[Tag::Customer][Tag::Invoice];
$this->vatAmount = isset($invoicePart[Meta::InvoiceVatAmount]) ? $invoicePart[Meta::InvoiceVatAmount] : $invoicePart[Meta::InvoiceAmountInc] - $invoicePart[Meta::InvoiceAmount];
$this->invoiceAmount = isset($invoicePart[Meta::InvoiceAmount]) ? $invoicePart[Meta::InvoiceAmount] : $invoicePart[Meta::InvoiceAmountInc] - $invoicePart[Meta::InvoiceVatAmount];
// The vat amount to divide over the non completed lines is the total vat
// amount of the invoice minus all known vat amounts per line.
$this->vat2Divide = (float) $this->vatAmount;
foreach ($invoicePart[Tag::Line] as $line) {
if ($line[Meta::VatRateSource] !== Creator::VatRateSource_Strategy) {
// Deduct the vat amount from this line: if set, deduct it directly,
// otherwise calculate the vat amount using the vat rate and unit price.
if (isset($line[Meta::VatAmount])) {
$this->vat2Divide -= $line[Meta::VatAmount] * $line[Tag::Quantity];
} else {
$this->vat2Divide -= ($line[Tag::VatRate] / 100.0) * $line[Tag::UnitPrice] * $line[Tag::Quantity];
}
}
}
} | php | protected function initAmounts()
{
$invoicePart = &$this->invoice[Tag::Customer][Tag::Invoice];
$this->vatAmount = isset($invoicePart[Meta::InvoiceVatAmount]) ? $invoicePart[Meta::InvoiceVatAmount] : $invoicePart[Meta::InvoiceAmountInc] - $invoicePart[Meta::InvoiceAmount];
$this->invoiceAmount = isset($invoicePart[Meta::InvoiceAmount]) ? $invoicePart[Meta::InvoiceAmount] : $invoicePart[Meta::InvoiceAmountInc] - $invoicePart[Meta::InvoiceVatAmount];
// The vat amount to divide over the non completed lines is the total vat
// amount of the invoice minus all known vat amounts per line.
$this->vat2Divide = (float) $this->vatAmount;
foreach ($invoicePart[Tag::Line] as $line) {
if ($line[Meta::VatRateSource] !== Creator::VatRateSource_Strategy) {
// Deduct the vat amount from this line: if set, deduct it directly,
// otherwise calculate the vat amount using the vat rate and unit price.
if (isset($line[Meta::VatAmount])) {
$this->vat2Divide -= $line[Meta::VatAmount] * $line[Tag::Quantity];
} else {
$this->vat2Divide -= ($line[Tag::VatRate] / 100.0) * $line[Tag::UnitPrice] * $line[Tag::Quantity];
}
}
}
} | [
"protected",
"function",
"initAmounts",
"(",
")",
"{",
"$",
"invoicePart",
"=",
"&",
"$",
"this",
"->",
"invoice",
"[",
"Tag",
"::",
"Customer",
"]",
"[",
"Tag",
"::",
"Invoice",
"]",
";",
"$",
"this",
"->",
"vatAmount",
"=",
"isset",
"(",
"$",
"invo... | Initializes the amount properties.
to be able to calculate the amounts, at least 2 of the 3 meta amounts
meta-invoice-vatamount, meta-invoice-amountinc, or meta-invoice-amount must
be known. | [
"Initializes",
"the",
"amount",
"properties",
"."
] | 82f8d6c9c4929c41948c97d6cfdfac3f27c37255 | https://github.com/SIELOnline/libAcumulus/blob/82f8d6c9c4929c41948c97d6cfdfac3f27c37255/src/Invoice/CompletorStrategyBase.php#L199-L219 | train |
SIELOnline/libAcumulus | src/Invoice/CompletorStrategyBase.php | CompletorStrategyBase.getVatBreakDownMinRate | protected function getVatBreakDownMinRate()
{
$result = array(Tag::VatRate => PHP_INT_MAX);
foreach ($this->vatBreakdown as $breakDown) {
if ($breakDown[Tag::VatRate] < $result[Tag::VatRate]) {
$result = $breakDown;
}
}
return $result;
} | php | protected function getVatBreakDownMinRate()
{
$result = array(Tag::VatRate => PHP_INT_MAX);
foreach ($this->vatBreakdown as $breakDown) {
if ($breakDown[Tag::VatRate] < $result[Tag::VatRate]) {
$result = $breakDown;
}
}
return $result;
} | [
"protected",
"function",
"getVatBreakDownMinRate",
"(",
")",
"{",
"$",
"result",
"=",
"array",
"(",
"Tag",
"::",
"VatRate",
"=>",
"PHP_INT_MAX",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"vatBreakdown",
"as",
"$",
"breakDown",
")",
"{",
"if",
"(",
"$"... | Returns the minimum vat rate on the invoice.
@return array
A vat rate overview: array with keys vatrate, vatamount, amount, count. | [
"Returns",
"the",
"minimum",
"vat",
"rate",
"on",
"the",
"invoice",
"."
] | 82f8d6c9c4929c41948c97d6cfdfac3f27c37255 | https://github.com/SIELOnline/libAcumulus/blob/82f8d6c9c4929c41948c97d6cfdfac3f27c37255/src/Invoice/CompletorStrategyBase.php#L272-L281 | train |
SIELOnline/libAcumulus | src/Invoice/CompletorStrategyBase.php | CompletorStrategyBase.apply | public function apply()
{
$this->replacingLines = array();
$this->init();
if ($this->checkPreconditions()) {
return $this->execute();
} else {
if (!empty($this->invoice[Tag::Customer][Tag::Invoice][Meta::CompletorStrategyPreconditionFailed])) {
$this->invoice[Tag::Customer][Tag::Invoice][Meta::CompletorStrategyPreconditionFailed] .= ', ';
} else {
$this->invoice[Tag::Customer][Tag::Invoice][Meta::CompletorStrategyPreconditionFailed] = '';
}
$this->invoice[Tag::Customer][Tag::Invoice][Meta::CompletorStrategyPreconditionFailed] .= $this->getName();
return false;
}
} | php | public function apply()
{
$this->replacingLines = array();
$this->init();
if ($this->checkPreconditions()) {
return $this->execute();
} else {
if (!empty($this->invoice[Tag::Customer][Tag::Invoice][Meta::CompletorStrategyPreconditionFailed])) {
$this->invoice[Tag::Customer][Tag::Invoice][Meta::CompletorStrategyPreconditionFailed] .= ', ';
} else {
$this->invoice[Tag::Customer][Tag::Invoice][Meta::CompletorStrategyPreconditionFailed] = '';
}
$this->invoice[Tag::Customer][Tag::Invoice][Meta::CompletorStrategyPreconditionFailed] .= $this->getName();
return false;
}
} | [
"public",
"function",
"apply",
"(",
")",
"{",
"$",
"this",
"->",
"replacingLines",
"=",
"array",
"(",
")",
";",
"$",
"this",
"->",
"init",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"checkPreconditions",
"(",
")",
")",
"{",
"return",
"$",
"this",... | Applies the strategy to see if it results in a valid solution.
@return bool
Success. | [
"Applies",
"the",
"strategy",
"to",
"see",
"if",
"it",
"results",
"in",
"a",
"valid",
"solution",
"."
] | 82f8d6c9c4929c41948c97d6cfdfac3f27c37255 | https://github.com/SIELOnline/libAcumulus/blob/82f8d6c9c4929c41948c97d6cfdfac3f27c37255/src/Invoice/CompletorStrategyBase.php#L323-L338 | train |
SIELOnline/libAcumulus | src/Shop/BatchForm.php | BatchForm.getInvoiceSourceReferenceList | protected function getInvoiceSourceReferenceList(array $invoiceSources)
{
$result = array();
foreach ($invoiceSources as $invoiceSource) {
$result[] = $invoiceSource->getReference();
}
return '{' . implode(',', $result) . '}';
} | php | protected function getInvoiceSourceReferenceList(array $invoiceSources)
{
$result = array();
foreach ($invoiceSources as $invoiceSource) {
$result[] = $invoiceSource->getReference();
}
return '{' . implode(',', $result) . '}';
} | [
"protected",
"function",
"getInvoiceSourceReferenceList",
"(",
"array",
"$",
"invoiceSources",
")",
"{",
"$",
"result",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"invoiceSources",
"as",
"$",
"invoiceSource",
")",
"{",
"$",
"result",
"[",
"]",
"=",
... | Returns a formatted string with the list of ids of the given sources.
@param \Siel\Acumulus\Invoice\Source[] $invoiceSources
@return string
A loggable (formatted) string with a list of ids of the sources. | [
"Returns",
"a",
"formatted",
"string",
"with",
"the",
"list",
"of",
"ids",
"of",
"the",
"given",
"sources",
"."
] | 82f8d6c9c4929c41948c97d6cfdfac3f27c37255 | https://github.com/SIELOnline/libAcumulus/blob/82f8d6c9c4929c41948c97d6cfdfac3f27c37255/src/Shop/BatchForm.php#L303-L310 | train |
SIELOnline/libAcumulus | src/Shop/InvoiceManager.php | InvoiceManager.getSourcesByIdsOrSources | public function getSourcesByIdsOrSources($invoiceSourceType, array $idsOrSources)
{
$results = array();
foreach ($idsOrSources as $sourceId) {
$results[] = $this->getSourceByIdOrSource($invoiceSourceType, $sourceId);
}
return $results;
} | php | public function getSourcesByIdsOrSources($invoiceSourceType, array $idsOrSources)
{
$results = array();
foreach ($idsOrSources as $sourceId) {
$results[] = $this->getSourceByIdOrSource($invoiceSourceType, $sourceId);
}
return $results;
} | [
"public",
"function",
"getSourcesByIdsOrSources",
"(",
"$",
"invoiceSourceType",
",",
"array",
"$",
"idsOrSources",
")",
"{",
"$",
"results",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"idsOrSources",
"as",
"$",
"sourceId",
")",
"{",
"$",
"results",
... | Creates a set of Invoice Sources given their ids or shop specific sources.
@param string $invoiceSourceType
@param array $idsOrSources
An array with shop specific orders or credit notes or just their ids.
@return \Siel\Acumulus\Invoice\Source[]
A non keyed array with invoice Sources. | [
"Creates",
"a",
"set",
"of",
"Invoice",
"Sources",
"given",
"their",
"ids",
"or",
"shop",
"specific",
"sources",
"."
] | 82f8d6c9c4929c41948c97d6cfdfac3f27c37255 | https://github.com/SIELOnline/libAcumulus/blob/82f8d6c9c4929c41948c97d6cfdfac3f27c37255/src/Shop/InvoiceManager.php#L228-L235 | train |
SIELOnline/libAcumulus | src/Shop/InvoiceManager.php | InvoiceManager.sendMultiple | public function sendMultiple(array $invoiceSources, $forceSend, $dryRun, array &$log)
{
$this->getTranslator()->add(new ResultTranslations());
$errorLogged = false;
$success = true;
$time_limit = ini_get('max_execution_time');
foreach ($invoiceSources as $invoiceSource) {
// Try to keep the script running, but note that other systems
// involved, like the (Apache) web server, may have their own
// time-out. Use @ to prevent messages like "Warning:
// set_time_limit(): Cannot set max execution time limit due to
// system policy in ...".
if (!@set_time_limit($time_limit) && !$errorLogged) {
$this->getLog()->warning('InvoiceManager::sendMultiple(): could not set time limit.');
$errorLogged = true;
}
$result = $this->getInvoiceResult('InvoiceManager::sendMultiple()');
$result = $this->createAndSend($invoiceSource, $result, $forceSend, $dryRun);
$success = $success && !$result->hasError();
$this->getLog()->notice($this->getSendResultLogText($invoiceSource, $result));
$log[$invoiceSource->getId()] = $this->getSendResultLogText($invoiceSource, $result,Result::AddReqResp_Never);
}
return $success;
} | php | public function sendMultiple(array $invoiceSources, $forceSend, $dryRun, array &$log)
{
$this->getTranslator()->add(new ResultTranslations());
$errorLogged = false;
$success = true;
$time_limit = ini_get('max_execution_time');
foreach ($invoiceSources as $invoiceSource) {
// Try to keep the script running, but note that other systems
// involved, like the (Apache) web server, may have their own
// time-out. Use @ to prevent messages like "Warning:
// set_time_limit(): Cannot set max execution time limit due to
// system policy in ...".
if (!@set_time_limit($time_limit) && !$errorLogged) {
$this->getLog()->warning('InvoiceManager::sendMultiple(): could not set time limit.');
$errorLogged = true;
}
$result = $this->getInvoiceResult('InvoiceManager::sendMultiple()');
$result = $this->createAndSend($invoiceSource, $result, $forceSend, $dryRun);
$success = $success && !$result->hasError();
$this->getLog()->notice($this->getSendResultLogText($invoiceSource, $result));
$log[$invoiceSource->getId()] = $this->getSendResultLogText($invoiceSource, $result,Result::AddReqResp_Never);
}
return $success;
} | [
"public",
"function",
"sendMultiple",
"(",
"array",
"$",
"invoiceSources",
",",
"$",
"forceSend",
",",
"$",
"dryRun",
",",
"array",
"&",
"$",
"log",
")",
"{",
"$",
"this",
"->",
"getTranslator",
"(",
")",
"->",
"add",
"(",
"new",
"ResultTranslations",
"(... | Sends multiple invoices to Acumulus.
@param \Siel\Acumulus\Invoice\Source[] $invoiceSources
@param bool $forceSend
If true, force sending the invoices even if an invoice has already been
sent for a given invoice source.
@param bool $dryRun
If true, return the reason/status only but do not actually send the
invoice, nor mail the result or store the result.
@param string[] $log
@return bool
Success. | [
"Sends",
"multiple",
"invoices",
"to",
"Acumulus",
"."
] | 82f8d6c9c4929c41948c97d6cfdfac3f27c37255 | https://github.com/SIELOnline/libAcumulus/blob/82f8d6c9c4929c41948c97d6cfdfac3f27c37255/src/Shop/InvoiceManager.php#L267-L291 | train |
SIELOnline/libAcumulus | src/Shop/InvoiceManager.php | InvoiceManager.send1 | public function send1(Source $invoiceSource, $forceSend)
{
$this->getTranslator()->add(new ResultTranslations());
$result = $this->getInvoiceResult('InvoiceManager::send1()');
$result = $this->createAndSend($invoiceSource, $result, $forceSend);
$success = !$result->hasError();
$this->getLog()->notice($this->getSendResultLogText($invoiceSource, $result));
return $success;
} | php | public function send1(Source $invoiceSource, $forceSend)
{
$this->getTranslator()->add(new ResultTranslations());
$result = $this->getInvoiceResult('InvoiceManager::send1()');
$result = $this->createAndSend($invoiceSource, $result, $forceSend);
$success = !$result->hasError();
$this->getLog()->notice($this->getSendResultLogText($invoiceSource, $result));
return $success;
} | [
"public",
"function",
"send1",
"(",
"Source",
"$",
"invoiceSource",
",",
"$",
"forceSend",
")",
"{",
"$",
"this",
"->",
"getTranslator",
"(",
")",
"->",
"add",
"(",
"new",
"ResultTranslations",
"(",
")",
")",
";",
"$",
"result",
"=",
"$",
"this",
"->",... | Sends 1 invoice to Acumulus.
@param \Siel\Acumulus\Invoice\Source $invoiceSource
The invoice source to send the invoice for.
@param bool $forceSend
If true, force sending the invoices even if an invoice has already been
sent for a given invoice source.
@return bool
Success. | [
"Sends",
"1",
"invoice",
"to",
"Acumulus",
"."
] | 82f8d6c9c4929c41948c97d6cfdfac3f27c37255 | https://github.com/SIELOnline/libAcumulus/blob/82f8d6c9c4929c41948c97d6cfdfac3f27c37255/src/Shop/InvoiceManager.php#L304-L312 | train |
SIELOnline/libAcumulus | src/Shop/InvoiceManager.php | InvoiceManager.sourceStatusChange | public function sourceStatusChange(Source $invoiceSource)
{
$result = $this->getInvoiceResult('InvoiceManager::sourceStatusChange()');
$status = $invoiceSource->getStatus();
$shopEventSettings = $this->getConfig()->getShopEventSettings();
if ($invoiceSource->getType() === Source::Order) {
$doSend = in_array($status, $shopEventSettings['triggerOrderStatus']);
$arguments = array($status, implode(',', $shopEventSettings['triggerOrderStatus']));
$notSendReason = Result::NotSent_WrongStatus;
} else {
$doSend = $shopEventSettings['triggerCreditNoteEvent'] === PluginConfig::TriggerCreditNoteEvent_Create;
$arguments = array();
$notSendReason = Result::NotSent_TriggerCreditNoteEventNotEnabled;
}
if ($doSend) {
$result = $this->createAndSend($invoiceSource, $result);
// Add argument to send status, this will add the current status and
// the set of statuses on which to send to the log line.
$result->setSendStatus($result->getSendStatus(), $arguments);
} else {
$result->setSendStatus($notSendReason, $arguments);
}
$this->getLog()->notice($this->getSendResultLogText($invoiceSource, $result));
return $result;
} | php | public function sourceStatusChange(Source $invoiceSource)
{
$result = $this->getInvoiceResult('InvoiceManager::sourceStatusChange()');
$status = $invoiceSource->getStatus();
$shopEventSettings = $this->getConfig()->getShopEventSettings();
if ($invoiceSource->getType() === Source::Order) {
$doSend = in_array($status, $shopEventSettings['triggerOrderStatus']);
$arguments = array($status, implode(',', $shopEventSettings['triggerOrderStatus']));
$notSendReason = Result::NotSent_WrongStatus;
} else {
$doSend = $shopEventSettings['triggerCreditNoteEvent'] === PluginConfig::TriggerCreditNoteEvent_Create;
$arguments = array();
$notSendReason = Result::NotSent_TriggerCreditNoteEventNotEnabled;
}
if ($doSend) {
$result = $this->createAndSend($invoiceSource, $result);
// Add argument to send status, this will add the current status and
// the set of statuses on which to send to the log line.
$result->setSendStatus($result->getSendStatus(), $arguments);
} else {
$result->setSendStatus($notSendReason, $arguments);
}
$this->getLog()->notice($this->getSendResultLogText($invoiceSource, $result));
return $result;
} | [
"public",
"function",
"sourceStatusChange",
"(",
"Source",
"$",
"invoiceSource",
")",
"{",
"$",
"result",
"=",
"$",
"this",
"->",
"getInvoiceResult",
"(",
"'InvoiceManager::sourceStatusChange()'",
")",
";",
"$",
"status",
"=",
"$",
"invoiceSource",
"->",
"getStatu... | Processes an invoice source status change event.
For now we don't look at credit note statuses, they are always sent.
@param \Siel\Acumulus\Invoice\Source $invoiceSource
The source whose status has changed.
@return \Siel\Acumulus\Invoice\Result
The result of sending (or not sending) the invoice. | [
"Processes",
"an",
"invoice",
"source",
"status",
"change",
"event",
"."
] | 82f8d6c9c4929c41948c97d6cfdfac3f27c37255 | https://github.com/SIELOnline/libAcumulus/blob/82f8d6c9c4929c41948c97d6cfdfac3f27c37255/src/Shop/InvoiceManager.php#L325-L349 | train |
SIELOnline/libAcumulus | src/Shop/InvoiceManager.php | InvoiceManager.invoiceCreate | public function invoiceCreate(Source $invoiceSource)
{
$result = $this->getInvoiceResult('InvoiceManager::invoiceCreate()');
$shopEventSettings = $this->getConfig()->getShopEventSettings();
if ($shopEventSettings['triggerInvoiceEvent'] == PluginConfig::TriggerInvoiceEvent_Create) {
$result = $this->createAndSend($invoiceSource, $result);
} else {
$result->setSendStatus(Result::NotSent_TriggerInvoiceCreateNotEnabled);
}
$this->getLog()->notice($this->getSendResultLogText($invoiceSource, $result));
return $result;
} | php | public function invoiceCreate(Source $invoiceSource)
{
$result = $this->getInvoiceResult('InvoiceManager::invoiceCreate()');
$shopEventSettings = $this->getConfig()->getShopEventSettings();
if ($shopEventSettings['triggerInvoiceEvent'] == PluginConfig::TriggerInvoiceEvent_Create) {
$result = $this->createAndSend($invoiceSource, $result);
} else {
$result->setSendStatus(Result::NotSent_TriggerInvoiceCreateNotEnabled);
}
$this->getLog()->notice($this->getSendResultLogText($invoiceSource, $result));
return $result;
} | [
"public",
"function",
"invoiceCreate",
"(",
"Source",
"$",
"invoiceSource",
")",
"{",
"$",
"result",
"=",
"$",
"this",
"->",
"getInvoiceResult",
"(",
"'InvoiceManager::invoiceCreate()'",
")",
";",
"$",
"shopEventSettings",
"=",
"$",
"this",
"->",
"getConfig",
"(... | Processes an invoice create event.
@param \Siel\Acumulus\Invoice\Source $invoiceSource
The source for which a shop invoice was created.
@return \Siel\Acumulus\Invoice\Result
The result of sending (or not sending) the invoice. | [
"Processes",
"an",
"invoice",
"create",
"event",
"."
] | 82f8d6c9c4929c41948c97d6cfdfac3f27c37255 | https://github.com/SIELOnline/libAcumulus/blob/82f8d6c9c4929c41948c97d6cfdfac3f27c37255/src/Shop/InvoiceManager.php#L360-L371 | train |
SIELOnline/libAcumulus | src/Shop/InvoiceManager.php | InvoiceManager.invoiceSend | public function invoiceSend(Source $invoiceSource)
{
$result = $this->getInvoiceResult('InvoiceManager::invoiceSend()');
$shopEventSettings = $this->getConfig()->getShopEventSettings();
if ($shopEventSettings['triggerInvoiceEvent'] == PluginConfig::TriggerInvoiceEvent_Send) {
$result = $this->createAndSend($invoiceSource, $result);
} else {
$result->setSendStatus(Result::NotSent_TriggerInvoiceSentNotEnabled);
}
$this->getLog()->notice($this->getSendResultLogText($invoiceSource, $result));
return $result;
} | php | public function invoiceSend(Source $invoiceSource)
{
$result = $this->getInvoiceResult('InvoiceManager::invoiceSend()');
$shopEventSettings = $this->getConfig()->getShopEventSettings();
if ($shopEventSettings['triggerInvoiceEvent'] == PluginConfig::TriggerInvoiceEvent_Send) {
$result = $this->createAndSend($invoiceSource, $result);
} else {
$result->setSendStatus(Result::NotSent_TriggerInvoiceSentNotEnabled);
}
$this->getLog()->notice($this->getSendResultLogText($invoiceSource, $result));
return $result;
} | [
"public",
"function",
"invoiceSend",
"(",
"Source",
"$",
"invoiceSource",
")",
"{",
"$",
"result",
"=",
"$",
"this",
"->",
"getInvoiceResult",
"(",
"'InvoiceManager::invoiceSend()'",
")",
";",
"$",
"shopEventSettings",
"=",
"$",
"this",
"->",
"getConfig",
"(",
... | Processes a shop invoice send event.
This is the invoice created by the shop and that is now sent/mailed to
the customer.
@param \Siel\Acumulus\Invoice\Source $invoiceSource
The source for which a shop invoice was created.
@return \Siel\Acumulus\Invoice\Result
The result of sending (or not sending) the invoice. | [
"Processes",
"a",
"shop",
"invoice",
"send",
"event",
"."
] | 82f8d6c9c4929c41948c97d6cfdfac3f27c37255 | https://github.com/SIELOnline/libAcumulus/blob/82f8d6c9c4929c41948c97d6cfdfac3f27c37255/src/Shop/InvoiceManager.php#L385-L396 | train |
SIELOnline/libAcumulus | src/Shop/InvoiceManager.php | InvoiceManager.createAndSend | protected function createAndSend(Source $invoiceSource, Result $result, $forceSend = false, $dryRun = false)
{
$acumulusEntry = null;
if ($this->isTestMode()) {
$result->setSendStatus(Result::Send_TestMode);
} elseif (($acumulusEntry = $this->getAcumulusEntryManager()->getByInvoiceSource($invoiceSource, false)) === null) {
$result->setSendStatus(Result::Send_New);
} elseif ($forceSend) {
$result->setSendStatus(Result::Send_Forced);
} elseif ($acumulusEntry->hasLockExpired()) {
$result->setSendStatus(Result::Send_LockExpired);
} elseif ($acumulusEntry->isSendLock()) {
$result->setSendStatus(Result::NotSent_LockedForSending);
} else {
$result->setSendStatus(Result::NotSent_AlreadySent);
}
if (($result->getSendStatus() & Result::Send_Mask) !== 0) {
$invoice = $this->getCreator()->create($invoiceSource);
// Do not send 0-amount invoices, if set so.
$shopEventSettings = $this->getConfig()->getShopEventSettings();
if ($shopEventSettings['sendEmptyInvoice'] || !$this->isEmptyInvoice($invoice)) {
// Trigger the InvoiceCreated event.
$this->triggerInvoiceCreated($invoice, $invoiceSource, $result);
// If the invoice is not set to null, we continue by completing it.
if ($invoice !== null) {
$invoice = $this->getCompletor()->complete($invoice, $invoiceSource, $result);
// Trigger the InvoiceCompleted event.
$this->triggerInvoiceSendBefore($invoice, $invoiceSource, $result);
// If the invoice is not set to null, we continue by sending it.
if ($invoice !== null) {
if (!$result->hasError()) {
if (!$dryRun) {
$result = $this->lockAndSend($invoice, $invoiceSource, $result);
} else {
$result->setSendStatus(Result::NotSent_DryRun);
}
} else {
$result->setSendStatus(Result::NotSent_LocalErrors);
}
} else {
$result->setSendStatus(Result::NotSent_EventInvoiceCompleted);
}
} else {
$result->setSendStatus(Result::NotSent_EventInvoiceCreated);
}
} else {
$result->setSendStatus(Result::NotSent_EmptyInvoice);
}
}
return $result;
} | php | protected function createAndSend(Source $invoiceSource, Result $result, $forceSend = false, $dryRun = false)
{
$acumulusEntry = null;
if ($this->isTestMode()) {
$result->setSendStatus(Result::Send_TestMode);
} elseif (($acumulusEntry = $this->getAcumulusEntryManager()->getByInvoiceSource($invoiceSource, false)) === null) {
$result->setSendStatus(Result::Send_New);
} elseif ($forceSend) {
$result->setSendStatus(Result::Send_Forced);
} elseif ($acumulusEntry->hasLockExpired()) {
$result->setSendStatus(Result::Send_LockExpired);
} elseif ($acumulusEntry->isSendLock()) {
$result->setSendStatus(Result::NotSent_LockedForSending);
} else {
$result->setSendStatus(Result::NotSent_AlreadySent);
}
if (($result->getSendStatus() & Result::Send_Mask) !== 0) {
$invoice = $this->getCreator()->create($invoiceSource);
// Do not send 0-amount invoices, if set so.
$shopEventSettings = $this->getConfig()->getShopEventSettings();
if ($shopEventSettings['sendEmptyInvoice'] || !$this->isEmptyInvoice($invoice)) {
// Trigger the InvoiceCreated event.
$this->triggerInvoiceCreated($invoice, $invoiceSource, $result);
// If the invoice is not set to null, we continue by completing it.
if ($invoice !== null) {
$invoice = $this->getCompletor()->complete($invoice, $invoiceSource, $result);
// Trigger the InvoiceCompleted event.
$this->triggerInvoiceSendBefore($invoice, $invoiceSource, $result);
// If the invoice is not set to null, we continue by sending it.
if ($invoice !== null) {
if (!$result->hasError()) {
if (!$dryRun) {
$result = $this->lockAndSend($invoice, $invoiceSource, $result);
} else {
$result->setSendStatus(Result::NotSent_DryRun);
}
} else {
$result->setSendStatus(Result::NotSent_LocalErrors);
}
} else {
$result->setSendStatus(Result::NotSent_EventInvoiceCompleted);
}
} else {
$result->setSendStatus(Result::NotSent_EventInvoiceCreated);
}
} else {
$result->setSendStatus(Result::NotSent_EmptyInvoice);
}
}
return $result;
} | [
"protected",
"function",
"createAndSend",
"(",
"Source",
"$",
"invoiceSource",
",",
"Result",
"$",
"result",
",",
"$",
"forceSend",
"=",
"false",
",",
"$",
"dryRun",
"=",
"false",
")",
"{",
"$",
"acumulusEntry",
"=",
"null",
";",
"if",
"(",
"$",
"this",
... | Creates and sends an invoice to Acumulus for an order.
@param \Siel\Acumulus\Invoice\Source $invoiceSource
The source object (order, credit note) for which the invoice was
created.
@param \Siel\Acumulus\Invoice\Result $result
@param bool $forceSend
If true, force sending the invoice even if an invoice has already been
sent for the given invoice source.
@param bool $dryRun
If true, return the reason/status only but do not actually send the
invoice, nor mail the result or store the result.
@return \Siel\Acumulus\Invoice\Result
The result of sending (or not sending) the invoice. | [
"Creates",
"and",
"sends",
"an",
"invoice",
"to",
"Acumulus",
"for",
"an",
"order",
"."
] | 82f8d6c9c4929c41948c97d6cfdfac3f27c37255 | https://github.com/SIELOnline/libAcumulus/blob/82f8d6c9c4929c41948c97d6cfdfac3f27c37255/src/Shop/InvoiceManager.php#L415-L471 | train |
SIELOnline/libAcumulus | src/Shop/InvoiceManager.php | InvoiceManager.lockAndSend | protected function lockAndSend(array $invoice, Source $invoiceSource, Result $result)
{
$doLock = !$this->isTestMode() && in_array($result->getSendStatus(), array(Result::Send_New, Result::Send_LockExpired));
if ($doLock) {
// Check if we may expect an expired lock and, if so, remove it.
if ($result->getSendStatus() === Result::Send_LockExpired) {
$lockStatus = $this->getAcumulusEntryManager()->deleteLock($invoiceSource);
if ($lockStatus === AcumulusEntry::Lock_BecameRealEntry) {
// Bail out: invoice already sent after all.
return $result->setSendStatus(Result::NotSent_AlreadySent);
}
}
// Acquire lock.
if (!$this->getAcumulusEntryManager()->lockForSending($invoiceSource)) {
// Bail out: Lock not acquired.
return $result->setSendStatus(Result::NotSent_LockedForSending);
}
}
try {
$result = $this->doSend($invoice, $invoiceSource, $result);
} catch (Exception $e) {
$result->setException($e);
}
// When everything went well, the lock will have been replaced by a real
// entry. So we only delete the lock in case of errors.
if ($doLock && $result->hasError()) {
// deleteLock() is expected to return AcumulusEntry::Lock_Deleted,
// so we don't act on that return status. With any of the other
// statuses it is unclear what happened and what the status will be
// in Acumulus: tell user to check.
if (($lockStatus = $this->getAcumulusEntryManager()->deleteLock($invoiceSource)) !== AcumulusEntry::Lock_Deleted) {
$code = $lockStatus === AcumulusEntry::Lock_NoLongerExists ? 903 : 904;
$result->addWarning($code, '',
sprintf($this->t('message_warning_delete_lock_failed'), $this->t($invoiceSource->getType())));
}
}
// Trigger the InvoiceSent event.
$this->triggerInvoiceSendAfter($invoice, $invoiceSource, $result);
// Send a mail if there are messages.
$this->mailInvoiceAddResult($result, $invoiceSource);
return $result;
} | php | protected function lockAndSend(array $invoice, Source $invoiceSource, Result $result)
{
$doLock = !$this->isTestMode() && in_array($result->getSendStatus(), array(Result::Send_New, Result::Send_LockExpired));
if ($doLock) {
// Check if we may expect an expired lock and, if so, remove it.
if ($result->getSendStatus() === Result::Send_LockExpired) {
$lockStatus = $this->getAcumulusEntryManager()->deleteLock($invoiceSource);
if ($lockStatus === AcumulusEntry::Lock_BecameRealEntry) {
// Bail out: invoice already sent after all.
return $result->setSendStatus(Result::NotSent_AlreadySent);
}
}
// Acquire lock.
if (!$this->getAcumulusEntryManager()->lockForSending($invoiceSource)) {
// Bail out: Lock not acquired.
return $result->setSendStatus(Result::NotSent_LockedForSending);
}
}
try {
$result = $this->doSend($invoice, $invoiceSource, $result);
} catch (Exception $e) {
$result->setException($e);
}
// When everything went well, the lock will have been replaced by a real
// entry. So we only delete the lock in case of errors.
if ($doLock && $result->hasError()) {
// deleteLock() is expected to return AcumulusEntry::Lock_Deleted,
// so we don't act on that return status. With any of the other
// statuses it is unclear what happened and what the status will be
// in Acumulus: tell user to check.
if (($lockStatus = $this->getAcumulusEntryManager()->deleteLock($invoiceSource)) !== AcumulusEntry::Lock_Deleted) {
$code = $lockStatus === AcumulusEntry::Lock_NoLongerExists ? 903 : 904;
$result->addWarning($code, '',
sprintf($this->t('message_warning_delete_lock_failed'), $this->t($invoiceSource->getType())));
}
}
// Trigger the InvoiceSent event.
$this->triggerInvoiceSendAfter($invoice, $invoiceSource, $result);
// Send a mail if there are messages.
$this->mailInvoiceAddResult($result, $invoiceSource);
return $result;
} | [
"protected",
"function",
"lockAndSend",
"(",
"array",
"$",
"invoice",
",",
"Source",
"$",
"invoiceSource",
",",
"Result",
"$",
"result",
")",
"{",
"$",
"doLock",
"=",
"!",
"$",
"this",
"->",
"isTestMode",
"(",
")",
"&&",
"in_array",
"(",
"$",
"result",
... | Locks, if needed, the invoice for sending and, if acquired, sends it.
NOTE: the mechanism used to lock and verify if we got the lock is not
atomic, nor fool proof for all possible situations. However, it is a
relatively easy to understand solution that will catch 99,9% of the
situations. If double sending still occurs, some warning mechanisms are
built in (were already built in) to delete one of the entries in Acumulus
and warn the user.
After sending the invoice:
- The invoice sent event gets triggered.
- A mail with the results may be sent.
@param \Siel\Acumulus\Invoice\Source $invoiceSource
@param array $invoice
@param \Siel\Acumulus\Invoice\Result $result
@return \Siel\Acumulus\Invoice\Result
The result structure of the invoice add API call merged with any local
messages. | [
"Locks",
"if",
"needed",
"the",
"invoice",
"for",
"sending",
"and",
"if",
"acquired",
"sends",
"it",
"."
] | 82f8d6c9c4929c41948c97d6cfdfac3f27c37255 | https://github.com/SIELOnline/libAcumulus/blob/82f8d6c9c4929c41948c97d6cfdfac3f27c37255/src/Shop/InvoiceManager.php#L495-L543 | train |
SIELOnline/libAcumulus | src/Shop/InvoiceManager.php | InvoiceManager.doSend | protected function doSend(array $invoice, Source $invoiceSource, Result $result)
{
/** @var \Siel\Acumulus\Invoice\Result $result */
$result = $this->getService()->invoiceAdd($invoice, $result);// Store the reference between the source of the webshop invoice and the
// Save Acumulus entry:
// - If we were sending in test mode or there were errors, no invoice
// will have been created in Acumulus: nothing to store.
// - If the invoice was sent as a concept, the entry id and token will
// be empty: store nulls.
if (!$this->isTestMode() && !$result->hasError()) {
// If we are going to overwrite an existing entry, we want to delete
// that from Acumulus.
$acumulusEntryManager = $this->getAcumulusEntryManager();
$oldEntry = $acumulusEntryManager->getByInvoiceSource($invoiceSource, true);
$response = $result->getResponse();
$saved = (bool) $acumulusEntryManager->save($invoiceSource,
empty($response['entryid']) ? null : $response['entryid'],
empty($response['token']) ? null : $response['token']
);
// Delete if there is an old entry and we successfully saved the new
// entry.
if ($saved && isset($oldEntry) && $oldEntry->getEntryId()) {
// But only if the old entry does not refer to a concept as
// concepts do not have an entry id and thus cannot be deleted.
$entryId = $oldEntry->getEntryId();
$deleteResult = $this->getService()->setDeleteStatus($entryId, API::Entry_Delete);
if ($deleteResult->hasMessages()) {
// Add messages to result but not if the entry has already
// the delete status or does not exist at all (anymore).
if ($deleteResult->hasCodeTag('P2XFELO12')) {
// Successfully deleted the old entry: add a warning so
// this info will be mailed to the user.
$result->addWarning(902, '',
sprintf($this->t('message_warning_old_entry_not_deleted'), $this->t($invoiceSource->getType()), $entryId));
} else {
$result->mergeMessages($deleteResult, true);
}
} else {
// Successfully deleted the old entry: add a notice so this
// info will be mailed to the user.
$result->addNotice(901, '',
sprintf($this->t('message_warning_old_entry_deleted'), $this->t($invoiceSource->getType()), $entryId));
}
}
}
return $result;
} | php | protected function doSend(array $invoice, Source $invoiceSource, Result $result)
{
/** @var \Siel\Acumulus\Invoice\Result $result */
$result = $this->getService()->invoiceAdd($invoice, $result);// Store the reference between the source of the webshop invoice and the
// Save Acumulus entry:
// - If we were sending in test mode or there were errors, no invoice
// will have been created in Acumulus: nothing to store.
// - If the invoice was sent as a concept, the entry id and token will
// be empty: store nulls.
if (!$this->isTestMode() && !$result->hasError()) {
// If we are going to overwrite an existing entry, we want to delete
// that from Acumulus.
$acumulusEntryManager = $this->getAcumulusEntryManager();
$oldEntry = $acumulusEntryManager->getByInvoiceSource($invoiceSource, true);
$response = $result->getResponse();
$saved = (bool) $acumulusEntryManager->save($invoiceSource,
empty($response['entryid']) ? null : $response['entryid'],
empty($response['token']) ? null : $response['token']
);
// Delete if there is an old entry and we successfully saved the new
// entry.
if ($saved && isset($oldEntry) && $oldEntry->getEntryId()) {
// But only if the old entry does not refer to a concept as
// concepts do not have an entry id and thus cannot be deleted.
$entryId = $oldEntry->getEntryId();
$deleteResult = $this->getService()->setDeleteStatus($entryId, API::Entry_Delete);
if ($deleteResult->hasMessages()) {
// Add messages to result but not if the entry has already
// the delete status or does not exist at all (anymore).
if ($deleteResult->hasCodeTag('P2XFELO12')) {
// Successfully deleted the old entry: add a warning so
// this info will be mailed to the user.
$result->addWarning(902, '',
sprintf($this->t('message_warning_old_entry_not_deleted'), $this->t($invoiceSource->getType()), $entryId));
} else {
$result->mergeMessages($deleteResult, true);
}
} else {
// Successfully deleted the old entry: add a notice so this
// info will be mailed to the user.
$result->addNotice(901, '',
sprintf($this->t('message_warning_old_entry_deleted'), $this->t($invoiceSource->getType()), $entryId));
}
}
}
return $result;
} | [
"protected",
"function",
"doSend",
"(",
"array",
"$",
"invoice",
",",
"Source",
"$",
"invoiceSource",
",",
"Result",
"$",
"result",
")",
"{",
"/** @var \\Siel\\Acumulus\\Invoice\\Result $result */",
"$",
"result",
"=",
"$",
"this",
"->",
"getService",
"(",
")",
... | Unconditionally sends the invoice and update the Acumulus entries table.
After sending the invoice:
- A successful result gets saved to the acumulus entries table.
- If an older submission exists, it will be deleted from Acumulus.
@param \Siel\Acumulus\Invoice\Source $invoiceSource
@param array $invoice
@param \Siel\Acumulus\Invoice\Result $result
@return \Siel\Acumulus\Invoice\Result
The result structure of the invoice add API call merged with any local
messages. | [
"Unconditionally",
"sends",
"the",
"invoice",
"and",
"update",
"the",
"Acumulus",
"entries",
"table",
"."
] | 82f8d6c9c4929c41948c97d6cfdfac3f27c37255 | https://github.com/SIELOnline/libAcumulus/blob/82f8d6c9c4929c41948c97d6cfdfac3f27c37255/src/Shop/InvoiceManager.php#L560-L609 | train |
SIELOnline/libAcumulus | src/Shop/InvoiceManager.php | InvoiceManager.getCol | protected function getCol(array $dbResults, $key)
{
$results = array();
foreach ($dbResults as $dbResult) {
$results[] = (int) $dbResult[$key];
}
return $results;
} | php | protected function getCol(array $dbResults, $key)
{
$results = array();
foreach ($dbResults as $dbResult) {
$results[] = (int) $dbResult[$key];
}
return $results;
} | [
"protected",
"function",
"getCol",
"(",
"array",
"$",
"dbResults",
",",
"$",
"key",
")",
"{",
"$",
"results",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"dbResults",
"as",
"$",
"dbResult",
")",
"{",
"$",
"results",
"[",
"]",
"=",
"(",
"int",... | Helper method to retrieve the values from 1 column of a query result.
@param array $dbResults
@param string $key
@return int[] | [
"Helper",
"method",
"to",
"retrieve",
"the",
"values",
"from",
"1",
"column",
"of",
"a",
"query",
"result",
"."
] | 82f8d6c9c4929c41948c97d6cfdfac3f27c37255 | https://github.com/SIELOnline/libAcumulus/blob/82f8d6c9c4929c41948c97d6cfdfac3f27c37255/src/Shop/InvoiceManager.php#L731-L738 | train |
SIELOnline/libAcumulus | src/Shop/InvoiceManager.php | InvoiceManager.getSendResultLogText | protected function getSendResultLogText(Source $invoiceSource, Result $result, $addReqResp = Result::AddReqResp_WithOther)
{
$invoiceSourceText = sprintf($this->t('message_invoice_source'),
$this->t($invoiceSource->getType()),
$invoiceSource->getReference()
);
$logMessage = sprintf($this->t('message_invoice_send'),
$result->getTrigger(),
$invoiceSourceText,
$result->getLogText($addReqResp)
);
return $logMessage;
} | php | protected function getSendResultLogText(Source $invoiceSource, Result $result, $addReqResp = Result::AddReqResp_WithOther)
{
$invoiceSourceText = sprintf($this->t('message_invoice_source'),
$this->t($invoiceSource->getType()),
$invoiceSource->getReference()
);
$logMessage = sprintf($this->t('message_invoice_send'),
$result->getTrigger(),
$invoiceSourceText,
$result->getLogText($addReqResp)
);
return $logMessage;
} | [
"protected",
"function",
"getSendResultLogText",
"(",
"Source",
"$",
"invoiceSource",
",",
"Result",
"$",
"result",
",",
"$",
"addReqResp",
"=",
"Result",
"::",
"AddReqResp_WithOther",
")",
"{",
"$",
"invoiceSourceText",
"=",
"sprintf",
"(",
"$",
"this",
"->",
... | Returns a string that details the result of the invoice sending.
@param \Siel\Acumulus\Invoice\Source $invoiceSource
@param \Siel\Acumulus\Invoice\Result $result
@param int $addReqResp
Whether to add the raw request and response.
One of the Result::AddReqResp_... constants
@return string | [
"Returns",
"a",
"string",
"that",
"details",
"the",
"result",
"of",
"the",
"invoice",
"sending",
"."
] | 82f8d6c9c4929c41948c97d6cfdfac3f27c37255 | https://github.com/SIELOnline/libAcumulus/blob/82f8d6c9c4929c41948c97d6cfdfac3f27c37255/src/Shop/InvoiceManager.php#L752-L764 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.