static function getProductosByFormId($formId) { $productos = GenericDao::find("Producto", array(array("formularioId", "=", $formId))); return Phinq::create($productos)->select(function ($item) { return $item->id; })->toArray(); }
static function getOrdenesDeCompraByUserId($data) { $ocs = array(); $conn = ExternalDao::getConnection(); $sql = "select * from vt080_oc_cabe where f_entrega between " . $data->date . " and DATEADD(day, u_dias_limite_entrega, '" . $data->date . "') "; if ($data->sucursalId) { $sql = $sql . " and (M_OC_MADRE = 'S' or C_SUCU_DESTINO_ALT = " . $data->sucursalId . ' ) '; } if (isset($data->proveedorId) && $data->proveedorId) { $sql = $sql . " and c_proveedor = " . $data->proveedorId; } else { if (isset($data->userId) && $data->userId) { $users_proveedor = SecurityDao::getUserProveedores($data->userId); $proveedorIds = Phinq::create($users_proveedor)->select(function ($item) { return $item->proveedorId; })->toArray(); $ids = implode(" , ", $proveedorIds); $sql = $sql . " and c_proveedor in ( " . $ids . ") "; } } $sql = $sql . " order by U_SUFIJO_OC "; $stmt = sqlsrv_query($conn, $sql, null); if ($stmt === false) { die(print_r(sqlsrv_errors(), true)); } while ($row = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_ASSOC)) { $oc = new \stdClass(); $oc->id = $row['U_SUFIJO_OC']; $oc->proveedorId = $row['C_PROVEEDOR']; $oc->fecha = $row['F_ENTREGA']->format('Y-m-d H:i:s'); $oc->diasLimiteEntrega = $row['U_DIAS_LIMITE_ENTREGA']; array_push($ocs, $oc); } sqlsrv_free_stmt($stmt); sqlsrv_close($conn); return $ocs; }
static function getFormEntryMessagesByFilter($filter) { $result = FormDao::getFormEntryMessagesByFilter($filter); $toCheck = Phinq::create($result)->firstOrDefault(function ($item) use($filter) { return $item->sender == $filter->sender && $item->checked == 0; }); if ($toCheck) { try { $transaction = GenericDao::beginTransaction(); $toCheck->checked = true; FormDao::updateFormEntryMessage($toCheck, $transaction); $transaction->commit(); } catch (\Exception $ex) { $transaction->rollBack(); } } return $result; }
/** * Compures the sum of all values in the collection * * Note that this always returns a float, so if the collection is not * contained entirely of numeric values, $lambda should be a transform * function that maps each element to a numeric value. Otherwise, the result * may be unexpected. * * @param Closure $lambda * @return float */ public function sum(Closure $lambda = null) { $collection = $lambda !== null ? Phinq::create($this->toArray())->select($lambda)->toArray() : $this->toArray(); return array_sum($collection); }
static function getOrdenesDeCompraByUserId($data) { $ocs = ExternalDao::getOrdenesDeCompraByUserId($data); $ocsSolicitudes = SolicitudesEntregaDao::getOrdenesDeCompraValid($data->userId, $data->sucursalId); $ocsAux = array(); foreach ($ocs as $oc) { $valid = true; $oc->entregaCompleta = false; if (!isset($data->solicitudEntregaId) || !$data->solicitudEntregaId) { foreach ($ocsSolicitudes as $actualOc) { if ($oc->id == $actualOc->ordenDeCompraId) { if ($actualOc->entregaCompleta) { $valid = false; break; } } } } else { if (isset($data->solicitudEntregaId) && $data->solicitudEntregaId) { $exists = Phinq::create($ocsSolicitudes)->any(function ($item) use($oc) { return $oc->id == $item->ordenDeCompraId; }); if ($exists) { $oc->solicitudEntregaId = $data->solicitudEntregaId; $otherSolicitud = !Phinq::create($ocsSolicitudes)->orderBy(function ($item) { return $item->entregaCompleta; })->any(function ($item) use($oc) { $oc->entregaCompleta = $item->entregaCompleta; return $oc->id == $item->ordenDeCompraId && ($item->solicitudEntregaId == $oc->solicitudEntregaId || $item->entregaCompleta); }); if ($otherSolicitud) { $valid = false; } } } } if (!$valid) { continue; } array_push($ocsAux, $oc); } foreach ($ocsAux as $oc) { $oc->razonSocial = ExternalDao::getProveedorById($oc->proveedorId)->razonSocial; } $result = new Response(new Result(), $ocsAux); return json_encode(Utils::utf8ize($result)); }
$pdf->Ln(6); $pdf->SetFont('Arial', 'B', 11); $pdf->Cell(90, 10, 'Fecha de alta:', 0, 0, 'R'); $pdf->SetFont('Arial', '', 10); $pdf->Cell(4); $pdf->Cell(60, 10, $solicitud->createDate, 0, 0, 'L'); $pdf->Ln(6); $pdf->SetFont('Arial', 'B', 11); $pdf->Cell(90, 10, 'Fecha de entrega:', 0, 0, 'R'); $pdf->SetFont('Arial', '', 10); $pdf->Cell(4); $pdf->Cell(60, 10, $solicitud->startsAt, 0, 0, 'L'); $pdf->Ln(6); $pdf->SetFont('Arial', 'B', 11); $pdf->Cell(90, 10, 'Ordenes de compra:', 0, 0, 'R'); $pdf->SetFont('Arial', '', 10); $pdf->Cell(4); $pdf->Cell(60, 10, join(',', \lib\phinq\Phinq::create($solicitud->ordenesDeCompra)->select(function ($oc) { return intval($oc->ordenDeCompraId); })->toArray()), 0, 0, 'L'); $pdf->Ln(6); $pdf->Ln(40); $pdf->Image($img, 75, null, 0, 0, 'png'); $pdf->Cell(0, 10, $barcode, 0, 0, 'C'); $pdf->Output(); ?>
static function updateUser($userDto) { $errors = SecurityAdmin::validateUser($userDto); $result = new Result(); if (sizeof($errors) == 0) { $user = SecurityDao::getUserById($userDto->id); $actualRoles = SecurityDao::getRolesByMail($user->mail); $actualRolesIds = Phinq::create($actualRoles)->select(function ($role) { return $role->id; })->toArray(); $rolesToAdd = Phinq::create($userDto->roles)->except($actualRolesIds); $rolesToDelete = Phinq::create($actualRolesIds)->except($userDto->roles); $actualProveedores = SecurityDao::getUserProveedores($user->id); $actualProveedoresIds = Phinq::create($actualProveedores)->select(function ($up) { return $up->proveedorId; })->toArray(); $newProveedoresIds = Phinq::create($userDto->proveedores)->select(function ($proveedor) { return $proveedor->id; })->toArray(); $proveedoresToAdd = Phinq::create($newProveedoresIds)->except($actualProveedoresIds); $proveedoresToDelete = Phinq::create($actualProveedoresIds)->except($newProveedoresIds); try { $transaction = GenericDao::beginTransaction(); if (isset($userDto->editPassword) && $userDto->editPassword) { $user->password = sha1($userDto->password); } $user->nick = $userDto->nick; $user->sucursalId = $userDto->sucursalId; $user->firstName = $userDto->firstName; $user->lastName = $userDto->lastName; $user->mail = $userDto->mail; $user->enabled = $userDto->enabled; $user->esFresco = $userDto->esFresco; $user->optionalMails = $userDto->optionalMails; $user->updateDate = date("Y-m-d H:i:s", time()); SecurityDao::updateUser($user, $transaction); foreach ($rolesToAdd as $roleId) { $user_role = new User_Role($user->id, $roleId); SecurityDao::AddRoleToUser($user_role, $transaction); } foreach ($rolesToDelete as $roleId) { $user_role = new User_Role($user->id, $roleId); SecurityDao::deleteRoleFromUser($user_role, $transaction); } foreach ($proveedoresToAdd as $proveedorId) { $user_proveedor = new User_Proveedor($user->id, $proveedorId); SecurityDao::addProveedorToUser($user_proveedor, $transaction); } foreach ($proveedoresToDelete as $proveedorId) { $user_proveedor = new User_Proveedor($user->id, $proveedorId); SecurityDao::deleteProveedorFromUser($user_proveedor, $transaction); } $transaction->commit(); } catch (\Exception $ex) { $transaction->rollBack(); $result->hasErrors = true; $result->messages = array($ex->getMessage()); } } else { $result->hasErrors = true; $result->messages = $errors; } $response = new Response($result, NULL); return json_encode($response); }
<td><?php echo $solicitud->createDate; ?> </td> </tr> <tr> <td><label>Fecha de entrega:</label></td> <td><?php echo $solicitud->startsAt; ?> </td> </tr> <tr> <td><label>Ordenes de compra:</label></td> <td><?php echo join(',', \lib\phinq\Phinq::create($solicitud->ordenesDeCompra)->select(function ($oc) { return intval($oc->ordenDeCompraId); })->toArray()); ?> </td> </tr> <tr> <td colspan="2" style="text-align: center; padding-top: 100px;"> <img id="barcode"> <script> $("#barcode").JsBarcode("<?php echo $barcode; ?> ", {width: 1, height:50}); </script> </td>
static function updateFaq($faqDto) { $faq = BaseDao::getFaqById($faqDto->id); $result = new Result(); try { $transaction = GenericDao::beginTransaction(); $faq->pregunta = $faqDto->pregunta; $faq->respuesta = $faqDto->respuesta; $faq->enabled = $faqDto->enabled; $faq->updateDate = date("Y-m-d H:i:s", time()); if ($faq->orden != $faqDto->orden) { $faqs = $data = BaseDao::getAllFaq(); $faqsFiltered = Phinq::create($faqs)->orderBy(function ($item) { return $item->orden; })->where(function ($item) use($faqDto) { return $item->id != $faqDto->id && $item->orden >= $faqDto->orden; })->toArray(); $firstOrden = $faqDto->orden; foreach ($faqsFiltered as $cf) { $firstOrden++; $cf->orden = $firstOrden; BaseDao::updateFaq($cf, $transaction); } } $faq->orden = $faqDto->orden; BaseDao::updateFaq($faq, $transaction); $transaction->commit(); } catch (\Exception $ex) { $transaction->rollBack(); $result->hasErrors = true; $result->messages = array($ex->getMessage()); } $response = new Response($result, NULL); return json_encode($response); }