first attempt to record client

This commit is contained in:
Kayn Ty 2018-04-10 10:16:23 +02:00
parent cada22694d
commit 013c990540
4 changed files with 136 additions and 10 deletions

View File

@ -56,7 +56,8 @@
</div>
<div class="row">
<div class="col">
<button class="btn btn-primary btn-block" id="validate_selling" ng-click="sendForm()">
<button class="btn btn-primary btn-block" id="validate_selling" ng-click="sendForm()"
ng-disabled="!paidAmount">
<i class="fa fa-check"></i>
Valider
</button>

View File

@ -2,6 +2,8 @@
namespace AppBundle\Controller;
use AppBundle\Entity\ProductSold;
use AppBundle\Entity\SellRecord;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\JsonResponse;
@ -120,20 +122,60 @@ class DefaultController extends Controller {
public function addSellingAction( Request $request ) {
// var_dump( $request->request );
// die();
$json = json_decode( $request->getContent() );
// link selling record with user, festival
$json = json_decode( $request->getContent(), true );
// var_dump( $json );
// die();
$currentUser = $this->getUser();
$m = $this->getDoctrine()->getManager();
$newSellRecord = new SellRecord();
// sort user categories
$myCategories = $m->getRepository( 'AppBundle:ProductCategory' )->findAll();
$categoriesByID = [];
foreach ( $myCategories as $my_category ) {
$categoriesByID[ $my_category->getId() ] = $my_category;
}
$productsModels = $m->getRepository( 'AppBundle:Product' )->findAll();
$productsModelsByID = [];
foreach ( $productsModels as $product ) {
$productsModelsByID[ $product->getId() ] = $product;
}
foreach ( $json[ 'activeSelling' ] as $record ) {
var_dump( $categoriesByID[ $record[ 'category' ] ] );
$newProductSold = new ProductSold();
// $newProductSold->setCategory( $categoriesByID[ $record[ 'category' ] ] );
$newProductSold->setName( $record[ 'name' ] );
$newProductSold->setPrice( $record[ 'price' ] );
$newProductSold->setProduct( $productsModelsByID[ $record[ 'id' ] ] );
$newProductSold->setUser( $currentUser );
$newProductSold->setSellRecords( $newSellRecord );
// link selling record with user, festival
$currentUser->addProductsSold( $newProductSold );
// persist all
$m->persist( $newProductSold );
}
$newSellRecord->setPaidByClient( 0 );
$newSellRecord->setAmount( 42 );
$newSellRecord->setDate( new \DateTime() );
// $newSellRecord->setPaidByClient( $json[ 'paidByClient' ] );
$currentUser->addSellRecords( $newSellRecord );
$m->persist( $newSellRecord );
$m->persist( $currentUser );
$m->flush();
// setup dates
// persist all
// fetch back history of selling
// echo "<pre>";
// var_dump( $request->getContent() );
//
// echo "</pre>";
$sellingRepo = $m->getRepository( 'AppBundle:SellRecord' );
$lastSellings = $sellingRepo->find( [], [ 'id' => 'desc' ], 0, 3 );
// return var_dump( $request->getContent() );
return new JsonResponse( [
"message" => "ok",
"recent_sellings" => [],
"recent_sellings" => $lastSellings,
"dump" => $json,
] );
}

View File

@ -10,12 +10,81 @@ use Doctrine\ORM\Mapping as ORM;
class ProductSold extends Product {
/**
* the stack of products for one client at one time
* @ORM\ManyToOne(targetEntity="SellRecord", inversedBy="productsSold")
*/
private $sellRecords;
public $sellRecords;
/**
* person who recorded the sell
* @ORM\ManyToOne(targetEntity="AppBundle\Entity\User", inversedBy="productsSold")
*/
private $user;
/**
* references the product from whom this line is inspired
* @ORM\ManyToOne(targetEntity="AppBundle\Entity\Product", inversedBy="productsSold")
*/
private $product;
/**
* @ORM\ManyToOne(targetEntity="ProductCategory", inversedBy="products")
*/
private $category;
/**
* @return mixed
*/
public function getCategory() {
return $this->category;
}
/**
* @param mixed $category
*/
public function setCategory( $category ) {
$this->category = $category;
}
/**
* @return mixed
*/
public function getSellRecords() {
return $this->sellRecords;
}
/**
* @param mixed $sellRecords
*/
public function setSellRecords( $sellRecords ) {
$this->sellRecords = $sellRecords;
}
/**
* @return mixed
*/
public function getUser() {
return $this->user;
}
/**
* @param mixed $user
*/
public function setUser( $user ) {
$this->user = $user;
}
/**
* @return mixed
*/
public function getProduct() {
return $this->product;
}
/**
* @param mixed $product
*/
public function setProduct( $product ) {
$this->product = $product;
}
}

View File

@ -52,6 +52,13 @@ class User extends BaseUser {
return $this->productsSold;
}
/**
* @return mixed
*/
public function addProductsSold( $product ) {
return $this->productsSold[] = $product;
}
/**
* @param mixed $productsSold
*/
@ -78,6 +85,13 @@ class User extends BaseUser {
$this->sellRecords = $sellRecords;
}
/**
* @param mixed $sellRecords
*/
public function addSellRecords( $sellRecords ) {
$this->sellRecords[] = $sellRecords;
}
/**
* @return mixed
*/