Skip to content

Commit

Permalink
adjusted auto-matching
Browse files Browse the repository at this point in the history
  • Loading branch information
BigAndini committed Mar 27, 2017
1 parent be2727d commit c90357e
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 11 deletions.
4 changes: 2 additions & 2 deletions module/Admin/src/Admin/Controller/BankaccountController.php
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ public function deleteUploadAction()
}
$em = $this->getServiceLocator()
->get('Doctrine\ORM\EntityManager');
$csv = $em->getRepository('ErsBase\Entity\PaymentTypeCsv')
$csv = $em->getRepository('ErsBase\Entity\BankAccountCsv')
->findOneBy(array('id' => $id));

$request = $this->getRequest();
Expand All @@ -460,7 +460,7 @@ public function deleteUploadAction()

if ($del == 'Yes') {
$id = (int) $request->getPost('id');
$csv = $em->getRepository('ErsBase\Entity\PaymentTypeCsv')
$csv = $em->getRepository('ErsBase\Entity\BankAccountCsv')
->findOneBy(array('id' => $id));
if($csv->hasMatch()) {
return $this->redirect()->toRoute('admin/bankaccount');
Expand Down
32 changes: 24 additions & 8 deletions module/Admin/src/Admin/Controller/CronController.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
use Zend\Console\Request as ConsoleRequest;

class CronController extends AbstractActionController {
protected $debug = false;

public function autoMatchingAction() {
/*
* Status of BankStatements
Expand All @@ -24,13 +26,17 @@ public function autoMatchingAction() {
* 4. disabled
*/

$this->debug = false;

$em = $this->getServiceLocator()
->get('Doctrine\ORM\EntityManager');

$statements = $em->getRepository('ErsBase\Entity\BankStatement')
->findAll();

echo "Phase 1: check ".count($statements)." statements".PHP_EOL.PHP_EOL;
if($this->debug) {
echo "Phase 1: check ".count($statements)." statements".PHP_EOL.PHP_EOL;
}
$longest_match = 0;
foreach($statements as $statement) {
$time_start = microtime(true);
Expand Down Expand Up @@ -79,7 +85,7 @@ public function autoMatchingAction() {
}
}
if(!$found) {
echo "WARNING: Unable to find any code in system.".PHP_EOL;
echo "WARNING: Unable to find any code in system: ";
echo $statement->getBankStatementColByNumber($statement_format->matchKey)->getValue().PHP_EOL;
}
$time_end = microtime(true);
Expand All @@ -89,7 +95,7 @@ public function autoMatchingAction() {
}
}
}
echo 'INFO: The longest match took '.$longest_match.' seconds.'.PHP_EOL;
#echo 'INFO: The longest match took '.$longest_match.' seconds.'.PHP_EOL;

/*
* check status of unpaid orders
Expand All @@ -102,22 +108,30 @@ public function autoMatchingAction() {

$orders = $qb->getQuery()->getResult();

echo PHP_EOL."Phase 2: check ".count($orders)." orders and set payment status.".PHP_EOL;
if($this->debug) {
echo PHP_EOL."Phase 2: check ".count($orders)." orders and set payment status.".PHP_EOL;
}

foreach($orders as $order) {
$statement_amount = $order->getStatementAmount();
$order_amount = $order->getSum();
if($order_amount == ($statement_amount*$statement_format->factor)) {
$paid = true;
echo ".";
if($this->debug) {
echo ".";
}
#echo "INFO: found match for order ".$order->getCode()->getValue()." ".$order_amount." <=> ".$statement_amount." (exact)".PHP_EOL;
} elseif($order_amount < $statement_amount) {
$paid = true;
echo "!";
if($this->debug) {
echo "!";
}
#echo "INFO: found match for order ".$order->getCode()->getValue()." ".$order_amount." <=> ".$statement_amount." (overpaid)".PHP_EOL;
} else {
$paid = false;
echo "-";
if($this->debug) {
echo "-";
}
#echo "INFO: found match for order ".$order->getCode()->getValue()." ".$order_amount." <=> ".$statement_amount." (partial)".PHP_EOL;
}
if($paid) {
Expand Down Expand Up @@ -156,7 +170,9 @@ public function autoMatchingAction() {
}
}
$em->flush();
echo PHP_EOL.PHP_EOL."done.".PHP_EOL;
if($this->debug) {
echo PHP_EOL.PHP_EOL."done.".PHP_EOL;
}
}

/*
Expand Down
2 changes: 1 addition & 1 deletion module/PreReg/Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ function($e) use ($sm) {
public function bootstrapSession($e)
{
if(\Zend\Console\Console::isConsole()) {
echo "not starting session -> console".PHP_EOL;
#echo "not starting session -> console".PHP_EOL;
return;
}

Expand Down

0 comments on commit c90357e

Please sign in to comment.