Пример #1
0
 public function gerarListagem()
 {
     $data = $this->find('list');
     if ($data) {
         return Set::apply("/", $data, function ($val) {
             return $val . " dias";
         }, array("type" => "map"));
     }
     return array();
 }
Пример #2
0
 public function retornaGraficoJson(array $default = null, array $data_inicio = null, array $data_fim = null)
 {
     $status = $this->consultaVolumeStatus($default, $data_inicio, $data_fim);
     $total_eventos = Set::apply('/GestaoEvento_Status/quantidade', $status, 'array_sum');
     foreach ($status as &$row) {
         $row['Graph']['id'] = $row[$this->alias][$this->primaryKey];
         $row['Graph']['value'] = (int) $row[$this->alias]['quantidade'];
         $row['Graph']['color'] = $row[$this->alias]['color'];
         $row['Graph']['highlight'] = $row[$this->alias]['color'];
         $row['Graph']['label'] = $row[$this->alias]['status'];
         $row['Graph']['perc'] = $row[$this->alias]['quantidade'] * 100 / $total_eventos;
     }
     return Hash::extract($status, '{n}.Graph');
 }
Пример #3
0
 public function formatDateFields($results, $dates, $format = "%d/%m/%Y")
 {
     if (!empty($dates)) {
         $setResult = function ($val, $key) use(&$results, $format) {
             $innerKey = explode("/", $key);
             $results[$innerKey[0]][$innerKey[1]][$innerKey[2]] = CakeTime::format($val, $format);
         };
         $extracted = Set::extract($results, "/{$this->alias}");
         $dateExtracted = Set::classicExtract($extracted, '{\\w+}.{\\w+}.{' . implode("|", $dates) . '}');
         $applied = Set::apply("/", $dateExtracted, function ($val) {
             return count(Set::filter($val)) > 0 ? $val : null;
         });
         if ($applied) {
             $flatten = Set::flatten($applied, "/");
             array_walk($flatten, $setResult);
         }
     }
     return $results;
 }
Пример #4
0
 /**
  * testSetApply method
  *
  * @return void
  */
 public function testApply()
 {
     $data = array(array('Movie' => array('id' => 1, 'title' => 'movie 3', 'rating' => 5)), array('Movie' => array('id' => 1, 'title' => 'movie 1', 'rating' => 1)), array('Movie' => array('id' => 1, 'title' => 'movie 2', 'rating' => 3)));
     $result = Set::apply('/Movie/rating', $data, 'array_sum');
     $expected = 9;
     $this->assertEquals($expected, $result);
     $result = Set::apply('/Movie/rating', $data, 'array_product');
     $expected = 15;
     $this->assertEquals($expected, $result);
     $result = Set::apply('/Movie/title', $data, 'ucfirst', array('type' => 'map'));
     $expected = array('Movie 3', 'Movie 1', 'Movie 2');
     $this->assertEquals($expected, $result);
     $result = Set::apply('/Movie/title', $data, 'strtoupper', array('type' => 'map'));
     $expected = array('MOVIE 3', 'MOVIE 1', 'MOVIE 2');
     $this->assertEquals($expected, $result);
     $result = Set::apply('/Movie/rating', $data, array('SetTest', 'method'), array('type' => 'reduce'));
     $expected = 9;
     $this->assertEquals($expected, $result);
     $result = Set::apply('/Movie/rating', $data, 'strtoupper', array('type' => 'non existing type'));
     $expected = NULL;
     $this->assertEquals($expected, $result);
 }
Пример #5
0
 /**
  * Signs a user up for an involvement opportunity
  *
  * Checks payment information, if needed. Creates childcare records, Roster records,
  * Payment records and runs credit cards.
  *
  * ### Passed args:
  * - integer `User` The (main) user id to sign up
  * - integer `Involvement` The involvement opportunity
  */
 public function add()
 {
     $userId = $this->passedArgs['User'];
     $involvementId = $this->passedArgs['Involvement'];
     if (!$userId || !$involvementId) {
         $this->cakeError('error404');
     }
     // get needed information about the user and this involvement
     $this->Roster->Involvement->contain(array('InvolvementType', 'Question'));
     $involvement = $this->Roster->Involvement->read(null, $involvementId);
     // can't sign up for inactive or past involvements
     if (!$involvement['Involvement']['active'] && !$involvement['Involvement']['previous']) {
         $this->Session->setFlash('Cannot sign up for an inactive or past event.', 'flash' . DS . 'failure');
         $this->redirect($this->emptyPage);
     }
     // create model to make use of validation
     $CreditCard = ClassRegistry::init('CreditCard');
     ///HouseholdMember/Household/HouseholdMember/User/Profile
     $this->Roster->User->contain(array('Profile', 'HouseholdMember' => array('Household' => array('HouseholdMember' => array('User' => array('Profile'))))));
     $user = $this->Roster->User->read(null, $userId);
     // they're submitting the form
     if (!empty($this->data)) {
         // first thing we'll do is validate all the data. if it all validates, we'll try to
         // process the credit card. if the credit card goes through, we'll add everyone to the
         // roster (including childcare) and save the payment info
         // extract info to check/save for roster
         $rValidates = true;
         $this->Roster->_validationErrors = array();
         foreach ($this->data['Adult'] as $roster => &$values) {
             if ($values['Roster']['user_id'] == 0) {
                 unset($this->data['Adult'][$roster]);
                 continue;
             }
             $values = $this->Roster->setDefaultData(array('roster' => $values, 'involvement' => $involvement, 'defaults' => $this->data['Default'], 'creditCard' => $this->data, 'payer' => $this->activeUser));
             // save validate success only if we haven't failed yet (so not to overwrite a failure)
             if ($rValidates) {
                 $rValidates = $this->Roster->saveAll($values, array('validate' => 'only'));
             } else {
                 // still validate this roster to generate errors
                 $this->Roster->saveAll($values, array('validate' => 'only'));
             }
             // save validation errors
             if (!empty($this->Roster->validationErrors)) {
                 $this->Roster->_validationErrors[$roster] = $this->Roster->validationErrors;
             }
         }
         // extract info to check/save for childcare
         $pValidates = true;
         $cValidates = true;
         if (isset($this->data['Child'])) {
             $possibleParents = Set::extract('/Adult/Roster/user_id', $this->data);
             foreach ($this->data['Child'] as $roster => &$child) {
                 if ($child['Roster']['user_id'] == 0) {
                     unset($this->data['Child'][$roster]);
                     continue;
                 }
                 // try to find the parent
                 $parent = null;
                 foreach ($possibleParents as $possibleParent) {
                     if ($this->Roster->User->HouseholdMember->Household->isMemberWith($possibleParent, $child['Roster']['user_id'])) {
                         $parent = $possibleParent;
                         break;
                     }
                 }
                 if (empty($parent)) {
                     $cValidates = $pValidates = false;
                 }
                 $child = $this->Roster->setDefaultData(array('roster' => $child, 'involvement' => $involvement, 'defaults' => $this->data['Default'], 'creditCard' => $this->data, 'payer' => $this->activeUser, 'parent' => $parent));
                 // save validate success only if we haven't failed yet (so not to overwrite a failure)
                 if ($cValidates) {
                     $cValidates = $this->Roster->saveAll($child, array('validate' => 'only'));
                 } else {
                     // still validate this roster to generate errors
                     $this->Roster->saveAll($child, array('validate' => 'only'));
                 }
             }
         }
         // check to make sure this doesn't exceed the roster limit
         $lValidates = true;
         $currentCount = $this->Roster->find('count', array('conditions' => array('Roster.involvement_id' => $involvement['Involvement']['id'], 'Roster.roster_status_id' => 1), 'contain' => false));
         $rosterCount = count($this->data['Adult']);
         $childCount = isset($this->data['Child']) ? count($this->data['Child']) : 0;
         if (!empty($involvement['Involvement']['roster_limit'])) {
             $lValidates = $rosterCount + $childCount + $currentCount <= $involvement['Involvement']['roster_limit'];
         } else {
             $lValidates = true;
         }
         $this->set('involvement', $involvement);
         // combine roster validation errors
         $this->Roster->validationErrors = $this->Roster->_validationErrors;
         $Adult = new Model(array('table' => false, 'name' => 'Adult'));
         $Adult->validationErrors = $this->Roster->_validationErrors;
         // check all validation before continuing with save
         if ($rosterCount > 0 && $lValidates && $rValidates && $cValidates && $pValidates) {
             // Now that we know that the data will save, let's run the credit card
             // get all signed up users (for their name)
             // calculate amount	(use array_values to reset keys)
             $amount = Set::apply('/Payment/amount', array_values($this->data['Adult']), 'array_sum');
             if (isset($this->data['Child'])) {
                 $amount += Set::apply('/Payment/amount', array_values($this->data['Child']), 'array_sum');
             }
             $signedUpIds = array_merge(Set::extract('/Adult/Roster/user_id', $this->data), Set::extract('/Child/Roster/user_id', $this->data));
             $signedupUsers = $this->Roster->User->Profile->find('all', array('conditions' => array('user_id' => $signedUpIds), 'contain' => false));
             $verb = count($signedupUsers) > 1 ? 'have' : 'has';
             foreach ($signedupUsers as $key => $signedupUser) {
                 $signedupUsers[$key]['answers'] = Set::extract('/Adult/Roster[user_id=' . $signedupUser['Profile']['user_id'] . ']/../Answer', $this->data);
             }
             $this->set(compact('verb', 'signedupUsers'));
             $signupSuccess = false;
             $paymentSuccess = false;
             $redirect = null;
             if ($involvement['Involvement']['take_payment'] && $this->data['Default']['payment_option_id'] > 0 && !$this->data['Default']['pay_later'] && $amount > 0) {
                 $description = implode(' and ', Set::extract('/Profile/name', $signedupUsers)) . ' ' . $verb . ' been signed up for ' . $involvement['InvolvementType']['name'] . ' ' . $involvement['Involvement']['name'];
                 $paymentOption = $this->Roster->PaymentOption->read(null, $this->data['Default']['payment_option_id']);
                 $this->data['CreditCard']['invoice_number'] = $paymentOption['PaymentOption']['account_code'];
                 $this->data['CreditCard']['description'] = $description;
                 $this->data['CreditCard']['email'] = $user['Profile']['primary_email'];
                 $this->data['CreditCard']['amount'] = $amount;
                 if ($CreditCard->save($this->data['CreditCard'])) {
                     // save main rosters
                     foreach ($this->data['Adult'] as $signuproster) {
                         $this->Roster->create();
                         // include transaction id
                         $signuproster['Payment'][0]['transaction_id'] = $CreditCard->transactionId;
                         $signuproster['Payment'][0]['number'] = substr($this->data['CreditCard']['credit_card_number'], -4);
                         $this->Roster->saveAll($signuproster, array('validate' => false));
                         $this->Notifier->notify(array('to' => $signuproster['Roster']['user_id'], 'template' => 'involvements_signup', 'subject' => 'Signed up for ' . $involvement['Involvement']['name']));
                     }
                     // save childcares
                     if (isset($this->data['Child']) && count($this->data['Child'])) {
                         foreach ($this->data['Child'] as $signupchild) {
                             $this->Roster->create();
                             // include transaction id
                             $signupchild['Payment'][0]['transaction_id'] = $CreditCard->transactionId;
                             $signupchild['Payment'][0]['number'] = substr($this->data['CreditCard']['credit_card_number'], -4);
                             $this->Roster->saveAll($signupchild, array('validate' => false));
                             $this->Notifier->notify(array('to' => $signupchild['Roster']['user_id'], 'template' => 'involvements_signup', 'subject' => 'Signed up for ' . $involvement['Involvement']['name']));
                         }
                     }
                     $signupSuccess = true;
                     $paymentSuccess = true;
                     $this->Notifier->notify(array('to' => $this->activeUser['User']['id'], 'template' => 'payments_payment_made', 'subject' => 'Your payment has been made for ' . $involvement['InvolvementType']['name']));
                     $this->Session->setFlash('Your payment has been received and you have signed up for ' . $involvement['Involvement']['name'] . '.', 'flash' . DS . 'success');
                     $redirect = array('controller' => 'involvements', 'action' => 'view', 'Involvement' => $involvementId);
                 } else {
                     $this->validationErrors['CreditCard'] = $CreditCard->validationErrors;
                     $this->Session->setFlash('Unable to process payment.', 'flash' . DS . 'failure');
                 }
             } else {
                 // no credit card, just save as normal
                 // save main rosters
                 foreach ($this->data['Adult'] as $signuproster) {
                     $this->Roster->create();
                     $this->Roster->saveAll($signuproster, array('validate' => false));
                     $this->Notifier->notify(array('to' => $signuproster['Roster']['user_id'], 'template' => 'involvements_signup', 'subject' => 'You have signed up for ' . $involvement['Involvement']['name']));
                 }
                 // save childcares
                 if (isset($this->data['Child']) && count($this->data['Child'])) {
                     foreach ($this->data['Child'] as $signupchild) {
                         $this->Roster->create();
                         $this->Roster->saveAll($signupchild, array('validate' => false));
                         $this->Notifier->notify(array('to' => $signupchild['Roster']['user_id'], 'template' => 'involvements_signup', 'subject' => 'You have signed up for ' . $involvement['Involvement']['name']));
                     }
                 }
                 $signupSuccess = true;
                 $this->Session->setFlash('You have signed up for ' . $involvement['Involvement']['name'] . '.', 'flash' . DS . 'success');
                 $redirect = array('controller' => 'involvements', 'action' => 'view', 'Involvement' => $involvementId);
             }
             if ($signupSuccess) {
                 // notify leaders
                 $leaders = $this->Roster->Involvement->getLeaders($involvement['Involvement']['id']);
                 if ($amount > 0) {
                     $this->set('amount', $amount);
                 }
                 foreach ($leaders as $leader) {
                     $paid = $paymentSuccess ? 'and paid for ' : null;
                     $this->Notifier->notify(array('to' => $leader, 'template' => 'involvements_signup_leader', 'subject' => 'New user(s) signed up ' . $paid . $involvement['Involvement']['name']));
                     if ($rosterCount + $childCount + $currentCount == $involvement['Involvement']['roster_limit']) {
                         $this->Notifier->notify(array('to' => $leader, 'template' => 'rosters_filled', 'subject' => $involvement['Involvement']['name'] . ' roster filled'));
                     }
                 }
                 // if it's a child being signed up, notify the household contact(s)
                 foreach ($signedupUsers as $signedupUser) {
                     if ($signedupUser['Profile']['child']) {
                         $households = $this->Roster->User->HouseholdMember->find('all', array('conditions' => array('HouseholdMember.user_id' => $signedupUser['Profile']['user_id'], 'HouseholdMember.confirmed' => true, 'not' => array('Household.contact_id' => $signedupUser['Profile']['user_id'])), 'contain' => array('Household')));
                         foreach ($households as $household) {
                             // let every contact (unless the contact is signing the person up)
                             $this->Notifier->notify(array('to' => $household['Household']['contact_id'], 'template' => 'involvements_signup_child', 'subject' => $signedupUser['Profile']['child'] . ' signed up for ' . $involvement['Involvement']['name']));
                         }
                     }
                 }
                 if ($redirect) {
                     $this->redirect($redirect);
                 }
             }
         } else {
             if (!$pValidates && isset($this->data['Child'])) {
                 $msg = 'A child cannot attend on his or her own! Please also select the adult who is bringing this child.';
             } elseif (!$lValidates) {
                 $msg = 'Cannot join ' . $involvement['Involvement']['name'] . '. The roster is full.';
             } elseif ($rosterCount == 0) {
                 $msg = 'Please choose everyone who is attending.';
             } else {
                 $msg = 'Cannot join ' . $involvement['Involvement']['name'] . '. Please try again.';
             }
             // set validation error so modal doesn't close
             if (empty($this->Roster->validationErrors)) {
                 $this->Roster->validationErrors = array('validation' => $msg);
             }
             $this->Session->setFlash($msg, 'flash' . DS . 'failure');
         }
     }
     // get user addresses for js
     $userAddresses = $this->Roster->User->Address->find('all', array('conditions' => array('foreign_key' => $userId, 'model' => 'User')));
     // format for select
     $addresses = Set::combine($userAddresses, '/Address/id', '/Address/name');
     // get involvement's payment options for js
     $involvementPaymentOptions = $this->Roster->PaymentOption->find('all', array('conditions' => array('involvement_id' => $involvementId)));
     // format for select
     $paymentOptions = Set::combine($involvementPaymentOptions, '/PaymentOption/id', '/PaymentOption/name');
     $paymentTypes = $this->Roster->Payment->PaymentType->find('all');
     $this->set('roles', $this->Roster->Role->find('list', array('conditions' => array('Role.id' => $this->Roster->Involvement->Ministry->Role->findRoles($involvement['Involvement']['ministry_id'])))));
     $this->set(compact('involvement', 'user', 'addresses', 'userAddresses', 'paymentOptions', 'involvementPaymentOptions', 'paymentTypes'));
 }
 private function removeIndisponiveisContagem($data)
 {
     return Set::filter(Set::apply("/", $data, function ($val) {
         return !in_array($val['Sobressalente_Equip_Serial']['cm_atual'], ['REPARO', 'FURTO', 'BAIXA']) ? $val : null;
     }, ['type' => 'map']));
 }
Пример #7
0
 /**
  * Returns a numerically indexed array of the latitude and longitude, based on
  * user-defined center or the average of the buffered addresses
  *
  * @return array
  */
 protected function _center()
 {
     if (!$this->center) {
         // set center to average points
         $this->center = array(Set::apply('/lat', $this->_addresses, 'array_sum') / count($this->_addresses), Set::apply('/lng', $this->_addresses, 'array_sum') / count($this->_addresses));
     }
     return $this->center;
 }
Пример #8
0
 /**
  * Adds a payment to a roster record
  *
  * @param string $id The roster id to attach the payment to
  */
 public function add($id)
 {
     // persist selected items through POST requests
     $this->here .= '/mspersist:1';
     if ($id) {
         $ids = array($id);
     } else {
         $ids = $this->_extractIds();
     }
     // get selected
     $users = $this->Payment->Roster->find('all', array('conditions' => array('Roster.id' => $ids), 'contain' => array('User' => array('Profile'))));
     $involvement = $this->Payment->Roster->Involvement->find('first', array('conditions' => array('Involvement.id' => $users[0]['Roster']['involvement_id']), 'contain' => array('InvolvementType')));
     // bind CreditCard to process the card
     $this->Payment->bindModel(array('hasOne' => array('CreditCard' => array('foreignKey' => false))));
     if (!empty($this->data)) {
         $paymentType = $this->Payment->PaymentType->read(array('name'), $this->data['Payment']['payment_type_id']);
         if (count($users) > 1) {
             // don't allow adding multiple credits
             $payForUsers = Set::extract('/Roster[balance>0]/..', $users);
         } else {
             $payForUsers = $users;
         }
         // get balance
         $balance = Set::apply('/Roster/balance', $payForUsers, 'array_sum');
         $amount = $this->data['Payment']['amount'] = preg_replace('/[^\\d\\.\\-]/', '', $this->data['Payment']['amount']);
         // set `amount` validation rule to reflect balance range and validate as it's
         // own field because we'll be splitting the payments up
         if ($amount > $balance) {
             $this->Payment->invalidate('amount', 'Your chosen amount must be at or under $' . $balance . '.');
         }
         // assuming all users still have a balance
         $avg = round($amount / count($payForUsers), 2);
         // build payment records (transaction id to be added later)
         $payments = array();
         foreach ($payForUsers as $user) {
             // get amount they can receive
             $amt = $avg <= $user['Roster']['balance'] ? $avg : $user['Roster']['balance'];
             // if less than the average, get the amount left to distribute elsewhere
             $amount -= $amt;
             // saving balance in here as well, to be removed later
             $payments[] = array('balance' => $user['Roster']['balance'] - $amt, 'user_id' => $user['Roster']['user_id'], 'roster_id' => $user['Roster']['id'], 'amount' => $amt, 'payment_type_id' => $this->data['Payment']['payment_type_id'], 'payment_placed_by' => $this->activeUser['User']['id']);
             // to associate with invoice number
             $paymentOption = $this->Payment->Roster->PaymentOption->read(null, $user['Roster']['payment_option_id']);
         }
         // if there was any left over, distribute to other users, otherwise, remove unwanted field
         foreach ($payments as &$payment) {
             if ($amount > 0) {
                 // get and then set the amount they can receive
                 $amt = $amount <= $payment['balance'] ? $amount : $payment['balance'];
                 $payment['amount'] += $amt;
                 $amount -= $amt;
             }
             unset($payment['balance']);
         }
         // create extra fields for credit card
         $verb = count($payForUsers) > 1 ? 'have' : 'has';
         $pVerb = count($payForUsers) > 1 ? 'had payments' : 'made a payment';
         // comma's and the like are not permitted by Authorize.net
         $description = implode(' and ', Set::extract('/User/Profile/name', $payForUsers)) . ' ' . $verb . ' ' . $pVerb . ' made for ' . $involvement['InvolvementType']['name'] . ' ' . $involvement['Involvement']['name'];
         $this->data['CreditCard']['invoice_number'] = $paymentOption['PaymentOption']['account_code'];
         $this->data['CreditCard']['description'] = $description;
         $this->data['CreditCard']['email'] = $this->activeUser['Profile']['primary_email'];
         $this->data['CreditCard']['amount'] = $this->data['Payment']['amount'];
         // make sure all the fields validate before charging the card, if there is one
         if (empty($this->Payment->validationErrors) && $this->Payment->saveAll($payments, array('validate' => 'only'))) {
             $isCreditCard = isset($this->data['CreditCard']) && isset($this->data['CreditCard']['credit_card_number']);
             // next, make sure the credit card gets authorized
             if ($isCreditCard) {
                 $pValidates = $this->Payment->CreditCard->save($this->data['CreditCard']);
             } else {
                 // no extra validation for other payment types
                 $pValidates = true;
             }
             if ($pValidates) {
                 // credit card as been charged, save the payment record
                 $this->Payment->create();
                 foreach ($payments as &$completePayment) {
                     if ($isCreditCard) {
                         // credit card
                         $completePayment['number'] = substr($this->data['CreditCard']['credit_card_number'], -4);
                         $completePayment['transaction_id'] = $this->Payment->CreditCard->transactionId;
                     } elseif (isset($this->data['Payment']['number'])) {
                         // other
                         $completePayment['number'] = $this->data['Payment']['number'];
                     }
                 }
                 $this->Payment->saveAll($payments, array('validate' => false));
                 $this->set('involvement', $involvement);
                 $this->set('payer', $this->activeUser);
                 $this->set('amount', $this->data['Payment']['amount']);
                 $leaders = $this->Payment->Roster->Involvement->getLeaders($involvement['Involvement']['id']);
                 $subject = $this->activeUser['Profile']['name'] . ' made a payment for ' . $involvement['Involvement']['name'];
                 foreach ($leaders as $leader) {
                     $this->Notifier->notify(array('to' => $leader, 'template' => 'payments_add_leader', 'subject' => $subject));
                 }
                 $this->Session->setFlash('Your payment has been received.', 'flash' . DS . 'success');
             } else {
                 $this->Session->setFlash('Unable to process payment.', 'flash' . DS . 'failure');
             }
         } else {
             $this->Session->setFlash('Unable to process payment. Please try again.', 'flash' . DS . 'failure');
         }
     }
     // get user addresses for js
     $userAddresses = $this->Payment->User->Address->find('all', array('conditions' => array('foreign_key' => $this->activeUser['User']['id'], 'model' => 'User')));
     // format for select
     $addresses = Set::combine($userAddresses, '/Address/id', '/Address/name');
     $paymentTypes = $this->Payment->PaymentType->find('all', array('conditions' => array('group_id' => $this->Payment->PaymentType->Group->findGroups($this->activeUser['Group']['id']))));
     $types = array_unique(Set::extract('/PaymentType/type', $paymentTypes));
     $types = array_intersect_key($this->Payment->PaymentType->types, array_flip($types));
     $this->set(compact('involvement', 'users', 'userAddresses', 'addresses', 'paymentTypes', 'types', 'mskey'));
 }
Пример #9
0
 /**
  * Tests acceptAll method
  *
  */
 public function testAcceptAll()
 {
     $data = $this->record;
     unset($data['Problem']['id']);
     $this->Problem->add('ProblematicArticle', 'article-1', 3, $data);
     $data['Problem']['type'] = 'other';
     $this->Problem->add('ProblematicArticle', 'article-1', 4, $data);
     $result = $this->Problem->acceptAll('ProblematicArticle', 'article-1');
     $this->assertTrue($result);
     $result = $this->Problem->find('all', array('fields' => 'accepted', 'conditions' => array('foreign_key' => 'article-1')));
     $this->assertEqual(3, Set::apply('/Problem/accepted', $result, 'array_sum'));
     $result = $this->Problem->acceptAll('ProblematicArticle', 'article-1', false);
     $this->assertTrue($result);
     $result = $this->Problem->find('all', array('fields' => 'accepted', 'conditions' => array('foreign_key' => 'article-1')));
     $this->assertEqual(0, Set::apply('/Problem/accepted', $result, 'array_sum'));
 }
 protected function gera_tabela_cm()
 {
     $data = array_map(function ($val) {
         return empty($val) ? null : $val;
     }, $this->request->data);
     $count = count(array_filter(array_slice($data, 2)));
     if ($count === 0 || $count === 1 && !empty($data['empresa'])) {
         return null;
     }
     $listagem = in_array($data['cm_origem'], ['FURTO', 'REPARO', 'BAIXA']) ? $this->Sobressalente_Equip_Serial->listaItensIndisponiveis($data['empresa'], $data['fornecedor'], $data['cm_origem'], $data['estacao_origem']) : $this->Sobressalente_Equip_Serial->listaItensPorCMEstacao($data['cm_origem'], $data['estacao_origem'], $data['empresa'], $data['fornecedor']);
     array_walk($listagem, function ($val, $key) use(&$listagem, &$data) {
         $listagem[$key]['itens'] = $this->Sobressalente_Equip_Serial->listaProdutoPorCM($val['Sobressalente_Equip_Descricao']['id_equip_descricao'], $data['cm_origem'], $data['estacao_origem'], $data['empresa']);
         $listagem[$key][0]['quantidade_indisponivel'] = count(Set::filter(Set::apply('/', $listagem[$key]['itens'], function ($val) {
             return in_array($val['Sobressalente_Equip_Serial']['cm_atual'], ['REPARO', 'BAIXA']) || isset($val['Sobressalente_Equip_Serial']['est_atual']) ? $val : null;
         }, ['type' => 'map'])));
         $listagem[$key][0]['quantidade'] = count($listagem[$key]['itens']);
         $listagem[$key][0]['quantidade_disponivel'] = $listagem[$key][0]['quantidade'] - $listagem[$key][0]['quantidade_indisponivel'];
     });
     return $listagem;
 }
Пример #11
0
 public function testAdd()
 {
     ClassRegistry::getObject('CreditCard')->getGateway()->setReturnValue('_request', '1||||||123456');
     $this->su(array('User' => array('id' => 1), 'Group' => array('id' => 1), 'Profile' => array('primary_email' => '*****@*****.**')));
     $this->Payments->Session->write('MultiSelect.test', array('selected' => array(2, 1)));
     $data = array('Payment' => array('payment_type_id' => 1, 'amount' => 100), 'CreditCard' => array('address_line_1' => '123 Main St.', 'address_line_2' => null, 'city' => 'Anytown', 'state' => 'CA', 'zip' => '12345', 'first_name' => 'Joe', 'last_name' => 'Schmoe', 'credit_card_number' => '4012888818888', 'cvv' => '123', 'expiration_date' => array('month' => '04', 'year' => '2080')));
     // too much
     $vars = $this->testAction('/payments/add/0/Involvement:1/mstoken:test', array('return' => 'vars', 'data' => $data));
     $results = $this->Payments->Payment->find('all', array('conditions' => array('Roster.involvement_id' => 1), 'contain' => array('Roster')));
     $this->assertEqual($results, array());
     // split between 2 people
     $notificationCountBefore = $this->Payments->Payment->User->Notification->find('count');
     $data['Payment']['amount'] = 10;
     $vars = $this->testAction('/payments/add/0/Involvement:1/mstoken:test', array('return' => 'vars', 'data' => $data));
     $results = $this->Payments->Payment->find('all', array('conditions' => array('Roster.involvement_id' => 1), 'contain' => array('Roster')));
     $amounts = Set::extract('/Payment/amount', $results);
     $expected = array(5, 5);
     $this->assertEqual($amounts, $expected);
     $numbers = Set::extract('/Payment/number', $results);
     $this->assertEqual($numbers, array(8888, 8888));
     $notificationCountAfter = $this->Payments->Payment->User->Notification->find('count');
     $this->assertEqual($notificationCountAfter - $notificationCountBefore, 1);
     // pay the rest of 1 person who only has 5 left, then the other 20 on the other
     $data['Payment']['amount'] = 25;
     $vars = $this->testAction('/payments/add/0/Involvement:1/mstoken:test', array('return' => 'vars', 'data' => $data));
     $results = $this->Payments->Payment->find('all', array('conditions' => array('Roster.involvement_id' => 1), 'contain' => array('Roster')));
     $total = Set::apply('/Payment/amount', $results, 'array_sum');
     $this->assertIdentical($total, 35.0);
     $results = Set::extract('/Payment/amount', $results);
     $expected = array(5, 5, 5, 20);
     $this->assertEqual($results, $expected);
     // add a cash credit
     $data = array('Payment' => array('amount' => -5, 'payment_type_id' => 2));
     $vars = $this->testAction('/payments/add/1/Involvement:1', array('return' => 'vars', 'data' => $data));
     $results = $this->Payments->Payment->find('all', array('conditions' => array('Payment.roster_id' => 1)));
     $total = Set::apply('/Payment/amount', $results, 'array_sum');
     $this->assertIdentical($total, 5.0);
     // check money sanitization
     $data = array('Payment' => array('amount' => '$5.00', 'payment_type_id' => 2));
     $vars = $this->testAction('/payments/add/1/Involvement:1', array('return' => 'vars', 'data' => $data));
     $result = $this->Payments->Payment->validationErrors;
     $expected = array();
     $this->assertEqual($result, $expected);
     $results = $this->Payments->Payment->find('all', array('conditions' => array('Payment.roster_id' => 1)));
     $total = Set::apply('/Payment/amount', $results, 'array_sum');
     $this->assertIdentical($total, 10.0);
 }