Skip to content

Commit

Permalink
Update plapayments to use DummyPayment class with no payment file output
Browse files Browse the repository at this point in the history
  • Loading branch information
steveblamey committed Jul 19, 2023
1 parent 7f29afc commit efaca2d
Show file tree
Hide file tree
Showing 9 changed files with 210 additions and 33 deletions.
17 changes: 17 additions & 0 deletions assets/css/uzerp/screen.less
Original file line number Diff line number Diff line change
Expand Up @@ -1296,6 +1296,23 @@
font-size: 7px;
}
}

/* modules/common/templates/elements/select_for_output.tpl */
div[data-action=select_for_output] {
.form-actions {
display: flex;
column-gap: 10px;
align-items: center;

.select-all {
order: 2;
}

input[name=save] {
order: 3;
}
}
}

/* we could use attribute selectors here, however we might not want to apply these styles everywhere */

Expand Down
19 changes: 11 additions & 8 deletions modules/common/templates/elements/select_for_output.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -108,14 +108,17 @@
{/data_table}
<input type="hidden" id="link" value="{$link}">
{paging}
Select count <input type='text' readonly id=selected_count name=selected_count value="{$count_selected}" class='numeric'>
{submit tags='none' name='save' value='Save Selection'}
{/form}
{form controller=$self.controller action='select_all' notags=true}
<input type='hidden' name='type' value={$type}>
<input type='hidden' name='id' value={$type_id}>
{submit tags='none' name='save' value='Select All'}
{/form}
<div class="form-actions">
<label for="selected_count">Select count</label> <input type='text' readonly id=selected_count name=selected_count value="{$count_selected}" class='numeric'>
{submit tags='none' name='save' value='Save Selection'}
</div>
{/form}
{form controller=$self.controller action='select_all' notags=true class='select-all'}
<input type='hidden' name='type' value={$type}>
<input type='hidden' name='id' value={$type_id}>
{submit tags='none' name='save' value='Select All'}
{/form}

<script type="text/javascript">
$(document).ready(function() {
legacyForceChange('#printtype');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ public function index($collection = null, $sh = '', &$c_query = null)
// Set context from calling module

$this->setSearch('pltransactionsSearch', 'payments', $s_data);
$this->_templateobject->orderby = ['created'];
parent::index(new PLPaymentCollection($this->_templateobject));

$sidebar = new SidebarController($this->view);

$sidebarlist=array();
Expand Down Expand Up @@ -81,15 +81,17 @@ public function view()
)
);

$sidebarlist['process_payment'] = array(
'tag'=>'Process Payment',
'link'=>array('modules' => $this->_modules
,'controller' => $this->name
,'action' => 'printDialog'
,'printaction' => 'make_batch_payment'
,$plpayment->idField => $plpayment->{$plpayment->idField}
)
);
if ($plpayment->getNoOutput() !== 't') {
$sidebarlist['process_payment'] = array(
'tag'=>'Process Payment',
'link'=>array('modules' => $this->_modules
,'controller' => $this->name
,'action' => 'printDialog'
,'printaction' => 'make_batch_payment'
,$plpayment->idField => $plpayment->{$plpayment->idField}
)
);
}
}

if ($plpayment->isProcessed())
Expand All @@ -109,6 +111,9 @@ public function view()
$this->view->register('sidebar',$sidebar);

$this->view->set('sidebar',$sidebar);

$r = $plpayment->getRemittanceOutputHeaders();
$this->view->set('outputs', $r);
}

public function process_override()
Expand Down Expand Up @@ -583,12 +588,48 @@ public function save_payments ()
{
$payclass = new $paytype->payment_class->class_name($this);
$payclass->validate($this->_data, $errors);
if (isset($payclass->no_output)) {
$payment->no_output = 't';
}
}

}

if (count($errors)==0 && $payment && $payment->savePLPayment($this->_data, $errors))
{
if (isset($payclass->no_output)) {
$paid_suppliers = array_keys($this->_data['PLTransaction']);
$supplier_has_remittance = new PLSupplierCollection();
$sh = new SearchHandler($supplier_has_remittance, false);
$cc = new ConstraintChain();
$cc->add(new Constraint('remittance_advice', 'IS', true));
if (count($paid_suppliers) > 1) {
$cc->add(new Constraint('id', 'in', '(' . implode(',', $paid_suppliers) . ')'));
} else {
$cc->add(new Constraint('id', '=', $paid_suppliers[0]));
}
$sh->addConstraintChain($cc);
$supplier_has_remittance->load($sh);

$payment->status = 'P';
$payment->save();
$flash->addMessage('Payment processed.');

if (count($supplier_has_remittance) > 0) {
// Allow the user to output a remittance advice
// for suppliers that need it
sendTo(
'pltransactions',
'select_remittances',
$this->_modules,
array('id'=>$payment->id)
);
}
}

// Not outputting remittance advice at this point.
// Return to the payment list where the user can
// select 'Proccess' to continue to the next stage.
sendTo($this->name
,'index'
,$this->_modules);
Expand All @@ -611,8 +652,28 @@ public function save_payments ()
{
$params['payment_type_id']=$this->_data['payment_type_id'];
}

$callback = function($errors) {
if (count($errors > 0)) {
return false;
}
};

// Kill off the progress bars
$progressNames = [
'checking_supplier_details',
'creating_pl_transactions',
'allocate_payments'
];
foreach($progressNames as $name) {
$progressbar = new Progressbar($name);
$progressbar->process([], $callback);
}

$flash->addErrors($errors);
if (isset($payclass->no_output)) {
sendBack();
}
$this->refresh();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function __construct($module = null, $action = null)

}

public function index()
public function index($collection = null, $sh = '', &$c_query = null)
{
$this->view->set('clickaction', 'view');

Expand Down Expand Up @@ -152,7 +152,8 @@ public function select_remittances ()
{
$pltransactions = new PLTransactionCollection();

$pltransactions->paidList($plpayment->id);
// Get payments for suppliers that require a remittance advice
$pltransactions->paidList($plpayment->id, true);

foreach ($pltransactions as $pltransaction) {
$pltransaction->gross_value = bcmul($pltransaction->gross_value,-1);
Expand Down Expand Up @@ -185,7 +186,7 @@ public function select_remittances ()
{
if (isset($output_details['identifier']))
{
$new_selection[$detail->id]['description'] = prettify($output_details['identifier']).' : '.$detail->$output_details['identifier'];
$new_selection[$detail->id]['description'] = prettify($output_details['identifier']).' : '.$detail->{$output_details['identifier']};
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -295,14 +295,24 @@ public function paymentClass()
return null;
}

public function outputPaymentFile()
/**
* Get no_output value
*
* no_output is not in the collection DB view.
* Not likely needed elsewhere and I'm too lazy
* to do a migration to add it in so that it
* appears in collections :-)
*
* @return bool
*/
public function getNoOutput()
{
$iclass_name = $this->paymentClass();
$c = new $iclass_name($this);
if (isset($c->noFile)) {
return false;
if (!isset($this->no_output)) {
$plpayment = new PLPayment();
$plpayment->load($this->id);
return $plpayment->no_output;
}
return true;
return $this->no_output;
}

public function isNewStatus()
Expand All @@ -314,6 +324,25 @@ public function isProcessed()
{
return ($this->status == 'P');
}

public function getRemittanceOutputHeaders()
{
// SQL to get the output header ids related to
// this PLPayment via the associated PLTransactions.
// Match the PLTransaction.ext_reference to the PLPayment.id
$SQL = "select distinct od.output_header_id, oh.created
from pltransactions as plt
join output_details od on od.select_id = plt.id
left join output_header as oh on oh.id = od.output_header_id
where plt.ext_reference = ? and oh.type = 'remittance'
order by oh.created";

$db = DB::Instance();
$query = $db->prepare($SQL);
$values = [$this->id];
$result = $db->execute($query, $values);
return $result;
}

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,17 @@ function summaryPayments()
$this->load($sh);
}

function paidList($payment_id)
function paidList($payment_id, $requires_remittance_advice=false)
{
$sh = new SearchHandler($this, false);

$sh->addConstraint(new Constraint('status', '=', 'P'));
$sh->addConstraint(new Constraint('transaction_type', '=', 'P'));
$sh->addConstraint(new Constraint('cross_ref', '=', $payment_id));

if ($requires_remittance_advice) {
$sh->addConstraint(new Constraint('remittance_advice', 'IS', true));
}

$sh->setOrderby(array('supplier', 'ext_reference'));

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

class DummyPayment
{
public $testprint = FALSE;
public $no_output = true;


function setData() {
return;
}

function constructPrint() {
return true;
}

function validate($data, &$errors)
{

$return = true;

if (isset($data['PLTransaction']))
{
$progressbar = new Progressbar('checking_supplier_details');

$callback = function($unused, $supplier_id) use (&$errors)
{

$supplier = DataObjectFactory::Factory('PLSupplier');
$supplier->load($supplier_id);

if (!$supplier->isLoaded())
{
$errors[] = 'Error checking supplier';
return false;
}


};

$return = $progressbar->process($data['PLTransaction'], $callback);

}

return $return;

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
{paging}
{data_table}
{heading_row}
{heading_cell field="created"}
Created
{/heading_cell}
{heading_cell field="payment_date"}
Payment Date
{/heading_cell}
Expand Down Expand Up @@ -39,8 +42,9 @@
{foreach name=transactions item=transaction from=$plpayments}
<tr>
<td align=left>
{link_to module=$module controller=$controller action='view' id=$transaction->id value=$transaction->payment_date|un_fix_date}
{link_to module=$module controller=$controller action='view' id=$transaction->id value=$transaction->created|un_fix_date}
</td>
<td align=left>{$transaction->payment_date|un_fix_date}</td>
<td align=left>{$transaction->getFormatted('status')}</td>
<td align=left>{$transaction->reference}</td>
<td align=center>{$transaction->number_transactions}</td>
Expand All @@ -49,7 +53,7 @@
<td align=left>{$transaction->currency}</td>
<td align=right>{$transaction->payment_total|string_format:"%.2f"}</td>
<td align=right>
{if $transaction->status=='N'}
{if $transaction->status=='N' && $transaction->getNoOutput() !== 't'}
{link_to module=$module controller=$controller action='printDialog' printaction='make_batch_payment' id=$transaction->id value='Process'}
{/if}
</td>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,17 @@
{view_data attribute='currency_id'}
{view_data attribute='payment_type_id'}
{view_data attribute='payment_total'}
{view_data attribute='remittance_printed'}
{view_data attribute='remittance_date'}
<dt>Remmitances printed</dt>
<dd><ul>
{foreach name=output item=output from=$outputs}
{assign d $output.created|un_fix_date}
{assign t $output.created|date_format:'%H:%M'}
{assign l $d|cat: ' - '|cat: $t}
<li>{link_to module=$module controller='pltransactions' action='output_detail' id=$output.output_header_id value=$l}</li>
{foreachelse}
None
{/foreach}
</dd></ul>
</dl>
{/with}
</div>
Expand Down

0 comments on commit efaca2d

Please sign in to comment.