Ejemplo n.º 1
0
    /**
     * testSocieteOther
     *
     * @param	Societe	$localobject	Company
     * @return	int		$id				Id of company
     *
     * @depends	testIdProfCheck
     * The depends says test is run only if previous is ok
     */
    public function testSocieteOther($localobject)
    {
    	global $conf,$user,$langs,$db;
		$conf=$this->savconf;
		$user=$this->savuser;
		$langs=$this->savlangs;
		$db=$this->savdb;

        $result=$localobject->set_as_client();
        print __METHOD__." id=".$localobject->id." result=".$result."\n";
        $this->assertLessThan($result, 0);

        $result=$localobject->set_price_level(1,$user);
        print __METHOD__." id=".$localobject->id." result=".$result."\n";
        $this->assertLessThan($result, 0);

        $result=$localobject->set_remise_client(10,'Gift',$user);
        print __METHOD__." id=".$localobject->id." result=".$result."\n";
        $this->assertLessThan($result, 0);

        $result=$localobject->getNomUrl(1);
        print __METHOD__." id=".$localobject->id." result=".$result."\n";
        $this->assertNotEquals($result, '');

        $result=$localobject->isInEEC();
        print __METHOD__." id=".$localobject->id." country_code=".$this->country_code." result=".$result."\n";
        $this->assertTrue(true, $result);

        $localobject->info($localobject->id);
        print __METHOD__." localobject->date_creation=".$localobject->date_creation."\n";
        $this->assertNotEquals($localobject->date_creation, '');

        return $localobject->id;
    }
Ejemplo n.º 2
0
 /**
  *  Output an HTML select vat rate
  *
  *  @param	string	$htmlname           Nom champ html
  *  @param  float	$selectedrate       Forcage du taux tva pre-selectionne. Mettre '' pour aucun forcage.
  *  @param  Societe	$societe_vendeuse   Objet societe vendeuse
  *  @param  Societe	$societe_acheteuse  Objet societe acheteuse
  *  @param  int		$idprod             Id product
  *  @param  int		$info_bits          Miscellaneous information on line (1 for NPR)
  *  @param  int		$type               ''=Unknown, 0=Product, 1=Service (Used if idprod not defined)
  *                  					Si vendeur non assujeti a TVA, TVA par defaut=0. Fin de regle.
  *                  					Si le (pays vendeur = pays acheteur) alors la TVA par defaut=TVA du produit vendu. Fin de regle.
  *                  					Si (vendeur et acheteur dans Communaute europeenne) et bien vendu = moyen de transports neuf (auto, bateau, avion), TVA par defaut=0 (La TVA doit etre paye par l'acheteur au centre d'impots de son pays et non au vendeur). Fin de regle.
  *                  					Si (vendeur et acheteur dans Communaute europeenne) et bien vendu autre que transport neuf alors la TVA par defaut=TVA du produit vendu. Fin de regle.
  *                  					Sinon la TVA proposee par defaut=0. Fin de regle.
  *  @param	bool	$options_only		Return options only (for ajax treatment)
  *  @return	void
  */
 function load_tva($htmlname = 'tauxtva', $selectedrate = '', $societe_vendeuse = '', $societe_acheteuse = '', $idprod = 0, $info_bits = 0, $type = '', $options_only = false)
 {
     global $langs, $conf, $mysoc;
     $return = '';
     $txtva = array();
     $libtva = array();
     $nprtva = array();
     // Define defaultnpr and defaultttx
     $defaultnpr = $info_bits & 0x1;
     $defaultnpr = preg_match('/\\*/', $selectedrate) ? 1 : $defaultnpr;
     $defaulttx = str_replace('*', '', $selectedrate);
     // Check parameters
     if (is_object($societe_vendeuse) && !$societe_vendeuse->country_code) {
         if ($societe_vendeuse->id == $mysoc->id) {
             $return .= '<font class="error">' . $langs->trans("ErrorYourCountryIsNotDefined") . '</div>';
         } else {
             $return .= '<font class="error">' . $langs->trans("ErrorSupplierCountryIsNotDefined") . '</div>';
         }
         return $return;
     }
     //var_dump($societe_acheteuse);
     //print "name=$name, selectedrate=$selectedrate, seller=".$societe_vendeuse->country_code." buyer=".$societe_acheteuse->country_code." buyer is company=".$societe_acheteuse->isACompany()." idprod=$idprod, info_bits=$info_bits type=$type";
     //exit;
     // Get list of all VAT rates to show
     // First we defined code_pays to use to find list
     if (is_object($societe_vendeuse)) {
         $code_pays = "'" . $societe_vendeuse->country_code . "'";
     } else {
         $code_pays = "'" . $mysoc->country_code . "'";
         // Pour compatibilite ascendente
     }
     if (!empty($conf->global->SERVICE_ARE_ECOMMERCE_200238EC)) {
         // If option to have vat for end customer for services is on
         if (!$societe_vendeuse->isInEEC() && $societe_acheteuse->isInEEC() && !$societe_acheteuse->isACompany()) {
             // We also add the buyer
             if (is_numeric($type)) {
                 if ($type == 1) {
                     // We know product is a service
                     $code_pays .= ",'" . $societe_acheteuse->country_code . "'";
                 }
             } else {
                 if (!$idprod) {
                     // We don't know type of product
                     $code_pays .= ",'" . $societe_acheteuse->country_code . "'";
                 } else {
                     $prodstatic = new Product($this->db);
                     $prodstatic->fetch($idprod);
                     if ($prodstatic->type == 1) {
                         // We know product is a service
                         $code_pays .= ",'" . $societe_acheteuse->country_code . "'";
                     }
                 }
             }
         }
     }
     // Now we get list
     $num = $this->load_cache_vatrates($code_pays);
     if ($num > 0) {
         // Definition du taux a pre-selectionner (si defaulttx non force et donc vaut -1 ou '')
         if ($defaulttx < 0 || dol_strlen($defaulttx) == 0) {
             $defaulttx = get_default_tva($societe_vendeuse, $societe_acheteuse, $idprod);
             $defaultnpr = get_default_npr($societe_vendeuse, $societe_acheteuse, $idprod);
         }
         // Si taux par defaut n'a pu etre determine, on prend dernier de la liste.
         // Comme ils sont tries par ordre croissant, dernier = plus eleve = taux courant
         if ($defaulttx < 0 || dol_strlen($defaulttx) == 0) {
             $defaulttx = $this->cache_vatrates[$num - 1]['txtva'];
         }
         if (!$options_only) {
             $return .= '<select class="flat" id="' . $htmlname . '" name="' . $htmlname . '">';
         }
         foreach ($this->cache_vatrates as $rate) {
             $return .= '<option value="' . $rate['txtva'];
             $return .= $rate['nprtva'] ? '*' : '';
             $return .= '"';
             if ($rate['txtva'] == $defaulttx && $rate['nprtva'] == $defaultnpr) {
                 $return .= ' selected="selected"';
             }
             $return .= '>' . vatrate($rate['libtva']);
             $return .= $rate['nprtva'] ? ' *' : '';
             $return .= '</option>';
             $this->tva_taux_value[] = $rate['txtva'];
             $this->tva_taux_libelle[] = $rate['libtva'];
             $this->tva_taux_npr[] = $rate['nprtva'];
         }
         if (!$options_only) {
             $return .= '</select>';
         }
     } else {
         $return .= $this->error;
     }
     $this->num = $num;
     return $return;
 }